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
5
Other forums
Strip Slashes Help
I've got a script that i've downloaded of the net to edit multiple fields from my sql database, and
Generate PDF
Hi guys,
I would like to know if there is a way to generate pdf when clicking on a link. In f
scandir clients directory
hi,
how can i scandir the clients directory? i need a script that when i click a button it will u
Display certain image depending on time of year
Hi, I am new to these forums and would really appreciate some advice on a piece of coding I have don
php mysql script to find record
Hi,
Currently I have a simple table with 4 columns. A, B, C, D
If I want to find all
Undefined variable when using $_SERVER['PHP_SELF']
Hi guyz, please suggest me something...
On first.php I have one input field NAME, and on posting
What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is goin
code help - pagination
Hi all, I have this code, basically a user logs into my site and they get this page.
The pro
database design
Hi,
I got a page which allow candidate to type in their previous working experience,
I let
Update data to upper case in parent/child tables
Hi Gurus!
In production we have a product table and which is being reference by many tabl