PDO prepare and execute woe

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I am having an awful lot of trouble of getting the PDO layer to work  

example code:
$tmpArray = array (
':table' => 'session',
':id' => '4364564574574576',
':user_id' => '0',
':state' => '0',
':start' => '2006-08-10 00:00:00',
':last_update' => '2006-08-10 00:00:00',
':last_id_update' => '2006-08-10 00:00:00',
':ip' => '123456789',
':agent' => 'Opera',
':referer' => 'whatever.php',
':data' => 'whatever data');

$sql = 'INSERT INTO :table (id, user_id, state, start, last_update,  
last_id_update, ip, agent, referer, data) VALUES (

$sth = $dbh->prepare($sql);
try {
} catch (PDOException $e) {
 die('Error!: ' . $e->getMessage());


Error!: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an  
error in your SQL syntax; check the manual that corresponds to your MySQL  
server version for the right syntax to use near ''session' (id, user_id,  
state, start, last_update, last_id_update, ip, agent, re' at line 1

What gives?

If I hardcode the table in the SQL statement it seems to work fine. But this  
should work too shouldn't it?


Re: PDO prepare and execute woe

amygdala wrote:
Quoted text here. Click to load it

It's a bit frustrating, but you can't use the place holders in all
spots.  The exact places you can use it, I don't know.  It probably
depends on if the prepare() is emulated or not, and what the underlying
server supports.

Re: PDO prepare and execute woe

Quoted text here. Click to load it

Aha, i was afraid that that was the case :(

Site Timeline