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

112 Like 5 Dislike
Previous php-forum Next php-forum
Other php-forum

Display thumbnails as square while retaining aspect ratio
I am trying to figure out a way to make an image display as a square, for example 80x80 pixels, when

Find only certain URLs from page ... regex (semi-complete script)
Hi guys,

What I need to do is take a page & extract all the URLs from the page &a

Required to login help
I'm trying to set up my site so users have to be logged into the forum to access the site.I've been

extract a file from zip file
hi,
i know how to unzip a zip file in php, but is there a way to just extract a certain file only

Insert data in Mysql and move to another page
I'm stuck with this simple problem. I need to insert data in Mysql and then hit submit and move to a

Feed Maker
Hi all.
First of all I must say I am not a php developer so I am afraid I don't know much about i

Coding Critique
I was hoping someone could take a second and look down my code and see if they see any problems with

TemplatePower & AJAX
Hi all,



I'm currently implementing some AJAX features in my PHP-framework (which is b

Create PHP table grid help, please
I have a MySQL database setup, now it's time for the table (gridview) design in php. Here's the prob

first few characters only
hi, does anyone know how to use PHP to take the first few words of a text and limit them? i have see

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