Hi,
I am having an awful lot of trouble of getting the PDO layer to work
properly.
example code:
-----------------
$tmpArray = array (
':table' ='session',
':id' ='4364564574574 576',
':user_id' ='0',
':state' ='0',
':start' ='2006-08-10 00:00:00',
':last_update' ='2006-08-10 00:00:00',
':last_id_updat e' ='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(P DO::ATTR_ERRMOD E, PDO::ERRMODE_EX CEPTION);
$sth = $dbh->prepare($sql );
try {
$sth->execute($tmpAr ray);
} 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
I am having an awful lot of trouble of getting the PDO layer to work
properly.
example code:
-----------------
$tmpArray = array (
':table' ='session',
':id' ='4364564574574 576',
':user_id' ='0',
':state' ='0',
':start' ='2006-08-10 00:00:00',
':last_update' ='2006-08-10 00:00:00',
':last_id_updat e' ='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(P DO::ATTR_ERRMOD E, PDO::ERRMODE_EX CEPTION);
$sth = $dbh->prepare($sql );
try {
$sth->execute($tmpAr ray);
} 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
Comment