Reputation: 587
I'm using Symfony2 (2.3) and trying to write session data into db. I use the PDOSessionHandler with a MSSQL 2012 db (sqlsrv as driver) Unfortunately I always get a PDO Error:
'SQLSTATE[07002]: [Microsoft][SQL Server Native Client 11.0]COUNT field incorrect or syntax error'
The statement which is prepared by the PDOSessionHandler class is as follows:
MERGE INTO session WITH (HOLDLOCK) USING (SELECT 1 AS dummy) AS src ON (session_id = :id) WHEN NOT MATCHED THEN INSERT (session_id, session_value, session_time) VALUES (:id, :data, :time) WHEN MATCHED THEN UPDATE SET session_value = :data, session_time = :time;
From my point of view this seems to be incorrect, because the same parameters are used more than once. This is accoring to pdo manual not allowed: (http://php.net/manual/en/pdo.prepare.php)
You must include a unique parameter marker for each value you wish to pass in to the statement when you call PDOStatement::execute(). You cannot use a named parameter marker of the same name more than once in a prepared statement, unless emulation mode is on.
Is this a symfony2 bug or are I'm doing something wrong?
Thanks for your help!
Upvotes: 1
Views: 4470
Reputation: 45490
There are 2 workaround:
:id2
, :data2
, :time2
You enable ATTR_EMULATE_PREPARES
:
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
Upvotes: 2