PHP Object PDO Isn't Behaving As Advertised
Posted: Mon Jan 16, 2006 10:55 am
Greeting DevNetwork forum members!
I'm having a fundamental problem using PDO in a very simple context.
Here's the entire script. It connects to a DB2 dbase called 'SAMPLE'.
There is a table within SAMPLE called TEST2 and TEST2 has two columns, my_name and my_notes. The script:
And the output:
In my code, I specify "My Name" to go into the my_name column of this table, but it doesn't! Instead, the value for my_notes gets inserted into both columns! Anyone who knows what's wrong here, please reply to this post. Thanks!
I'm having a fundamental problem using PDO in a very simple context.
Here's the entire script. It connects to a DB2 dbase called 'SAMPLE'.
There is a table within SAMPLE called TEST2 and TEST2 has two columns, my_name and my_notes. The script:
Code: Select all
<?php
// Get a PDO database handle object
$dbh = new PDO("odbc:SAMPLE");
// Insert two values into database table ( NOT WORKING! )
$sth = $dbh->prepare("INSERT INTO test2 (my_name, my_notes) VALUES(?, ?)");
$sth->execute(array("My Name", "A note..."));
// Select all values from database table, print to stdout
$sth = $dbh->prepare("SELECT * FROM test2");
try { $sth->execute(); }
catch (PDOException $e) { exit($e->getMessage()); }
// Print rows just fetched
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { print_r($row); }
?>Code: Select all
Array
(
[MY_NAME] => A note...
[MY_NOTES] => A note...
)