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!

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

Php If in MySql query (hiding labels if a field is empty)
Okay, I've been trying to do this for a while, and I'm finally going to ask for help so I can get th

weird problem
last time, i did post a topic concerning why my page sometime will load as blank page when using IE.

Need help: how to catch acess of undefined class properties
Hello. I am learning OO with PHP and have hit a problem.
Some code runs as perfectly valid code,

Apart from cron
I need to run a php file every one hour. Is there any other solution apart from cron job?

Hit counter updating once per IP - IP HIT COUNTER
I have a hit counter, for the amount of views on a tutorial.
It'll do the query and then do..

Anti Spam Code
Ok where do i start? Probably by telling you I have very little working knowledge of PHP and that I

Pspell with my own dictionary
Hello!
I've tested two cases using pspell functions.
1)
Code: $dictionary_link = pspell_new

Is this possible? If one file assigned to an ID...
I have a page that lists property listings assigned to a specific user (a manage page), with brief t

Looking for help on using joining mysql tables and php....
Does anyone have any good links to references on how to pull mysql data, through joining tables and

Echo-ing MySQL content and Keep Formatting?
I have data in my MySQL such as:

QuoteBlah blah

Blah blah

etc
but when i ech

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