|
Posted by amygdala on 08/10/06 18:02
Hi,
I am having an awful lot of trouble of getting the PDO layer to work
properly.
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 (
:id,
:user_id,
:state,
:start,
:last_update,
:last_id_update,
:ip,
:agent,
:referer,
:data
)';
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $dbh->prepare($sql);
try {
$sth->execute($tmpArray);
} catch (PDOException $e) {
die('Error!: ' . $e->getMessage());
}
returns:
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?
Cheers
Navigation:
[Reply to this message]
|