PDO returns erroneous columns from within pdt


Posted on 16th Feb 2014 07:03 pm by admin

Hi All,

This is a truly weird behavior:
When using a simple pdo fetch, erroneous columns are returned!
Did you know?Explore Trending and Topic pages for more stories like this.

Steps to reproduce:
------------------------------------------------------------ -----------
1.create a table with 4 columns, such as:
CREATE TABLE `t1` (
`col1` int(11) DEFAULT NULL,
`col2` varchar(20) DEFAULT NULL,
`col3` int(11) DEFAULT NULL,
`col4` int(11) DEFAULT NULL
)
2. Insert some data:
INSERT INTO t1 VALUES (1, 'test', 2, 3);

3. Try the following code:
$pdo = new PDO("mysql:host=localhost;dbname=test", 'usr', 'pwd');
$pdoStatement = $pdo->query('select * from t1');
$dbResult = $pdoStatement->fetchAll(PDO::FETCH_ASSOC);
var_dump($dbResult);
------------------------------------------------------------ -------
This produces the results:
array(1) {
=>array(3) {
["col1"]=>
string(1) "1"
["col2"]=>
string(4) "test"
["t1"]=>
string(1) "2"
}

That is, instead of returning 4 columns named col1,col2,col3,col4,
only 3 columns are returned, col1, col2 and t1!
While t1 is the name of the table!!!!

What's going on here (This drove me crazy at first )??

By the way, when running directly from under Apache this code produces the correct results. Is this some kind of a version issue? I'm running this from the latest release of eclipse pdt: PDT 2.1-SR1, Eclipse 3.5-SR1
Is there a latter one?

Many Thanks!
Vitaliy
Many Thanks!
Vitaliy
No comments posted yet

Your Answer:

Login to answer
112 Like 5 Dislike
Previous forums Next forums
Other forums

explode() function problem maybe
Hi I'm having trouble searching my database. When I type two words in the search field it only searc

double and single quotes in text fields acting up... help please
Single quotes, when entered into a text field, create an sql error upon Submit. It seems to create t

How to write on database when a link is clicked?
Hi, I have a list of products in a gridview. When the link is clicked currently it takes to an ext

Google Map
I have done Google Map Integration for one my project. But for that we need the "latitude and l

PHP Thumbnail Creation
Ok so i use this function to create thumbnails:

Code: function createthumb($name,$filename,$n

Getting Resource id #11 while trying to connect..
So i tried using "DEFINE" for the first time and im using the variables i defined to conne

Do something every fifth time?
I'm trying to write a loop, but I want it to do something different after every fifth instance. Like

Why does first ever HttpSendRequest take longer?
I promise this isn't as simple as it sounds. I'm wondering why the the first ever call to HttpSendRe

displaying email without attracting a ton of spam
Hello,

this is maybe the wrong place to ask.
How would you display an email address on a w

C - Reading a file into a byte array
Hi,

I'm trying to read a file into a byte array in C. I have to use C as this is for a loadru

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash