Hi there,
I’ve got some very strange behaviour here and was wondering if anybody has an idea what the issue could be…
I’m currently testing to see if storing the session data in a database table is beneficial for our application and so I’ve added this to my components as described in this post: Slow db session table…
// application components
'components'=>array(
...
'db_session'=>array(
'class' => 'CDbConnection',
'connectionString' => 'mysql:host=localhost;dbname=session_db',
'emulatePrepare' => true,
'username' => 'xyz',
'password' => 'xyz',
'charset' => 'utf8',
),
'session'=>array(
'class' => 'CDbHttpSession',
'connectionID' => 'db_session',
'autoCreateSessionTable' => false,
),
...
),
I’ve also created the DB with the table ‘YiiSession’ and the columns with index as described in the post above.
Now the strange thing is that when I try to log in the new session entry is created in the database as expected but when it comes to ‘public function writeSession($id,$data)’ in CDbHttpSession there is this line:
if($db->createCommand()->select('id')->from($this->sessionTableName)->where('id=:id',array(':id'=>$id))->queryScalar()===false)
The queryScalar() here always returns ‘false’, no matter if the ID actually exists in the table or not. Which in turn produces this error message:
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation:
1062 Duplicate entry 'b5pesr9jmdnu6hgc6nelfmrjso8733f8' for key 'PRIMARY'.
The SQL statement executed was: INSERT INTO `YiiSession` (`id`, `data`, `expire`) VALUES (:id, :data, :expire)
So far I’ve tried it with different databases and even adding the YiiSession-table to another existing database, always with the same result.
If I do a normal ‘SELECT count(*)’ with the same parameters I get an accurate result.
Could it be a PDO-bug or something like that?
I’m forced to work on SLES11 SP2, PHP 5.3.8, pdo_mysql: mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $
Any ideas would be greatly appreciated.