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

send message to the java application
Oracle 10g with Windows platform.

I have a java application that periodically pings the d

Replacing a string on click of a button
Hi! Is there a way to replace a string on a click of a text link?

This is what I've come up w

How to return to a previous page after running a PHP script
I'm having a bit of a melt down here because I think this should be really easy but can't work it ou

Need help with an email blocker for a guessbook
I am new with php and here is a simple guessbook page but I am being hit with spam from a group of t

Coding question?
Hey guys, I have a quick question. If I want to make a way for people to pay for health in my game,

How would I do "Users not logged in since *** delete them"
I know how I would set this up, and delete the user roughly.
I'll create a table called "Use

Update Database
Hi All,


I have a problem with this:

Code: [Select]<?php
session_start();

Issue Parsing XML into table
Hello all,

Im a bit new to php and new to phpfreaks. But thanks in advance for the help!
<

Help: calling function
Hi,
Is it possible to call a php function on page close?
If yes, could you explain how and whe

for some reason mysql query not working, not inserting, please check it out
This code is not inserting anything into my db, don't know why, the $_SESSION variable does contain

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