PDO returns erronous columns from pdt

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zz_vf_zz
Forum Newbie
Posts: 3
Joined: Wed Oct 14, 2009 10:22 am

PDO returns erronous columns from pdt

Post by zz_vf_zz »

This is a truly weird behavior:
When using a simple pdo fetch, erroneous columns are returned!

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) {
[0]=>
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!!!!

I'm running this from the latest release of eclipse pdt: PDT 2.1-SR1, Eclipse 3.5-SR1

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

Many Thanks!
Vitaliy
zz_vf_zz
Forum Newbie
Posts: 3
Joined: Wed Oct 14, 2009 10:22 am

Re: PDO returns erronous columns from pdt

Post by zz_vf_zz »

Hi all,

Here's an update: Managed to resolve the problem!

Here it goes for anyone who'll encounter this in the future:
The problem occurred due to an erroneous run\debug configurations in eclipse.
An older version of the PHP executable had been selected by default (5.2.10),
which caused the weird PDO behavior (compatibility issues??).

To resolve the issue, go in eclipse to Run->Run Configurations, choose your PHP script on the left pane,
and change in the right pane the php executable to the correct version (5.3.0 in my case).

Hope this will be helpful to someone,
Vitaliy
Post Reply