CDbHttpSession generate Null value for ‘test’ on code
Test code
$c = new CDbCriteria();
print_r(Yii::app()->session->itemAt('test'));
Yii::app()->session->add('test', $c);
Yii::app()->session->close();
My DB PostgreSql 8.4.4.
Look on the $data string end .
Check that symbol with code zero near each CComponent string:
"�CComponent�_e";N;s:14:"�CComponent�_m";N;}
DB doesnot save string with none utf8 characters.
CDbHttpSession
public function writeSession($id,$data)
{
// exception must be caught in session write handler
// http://us.php.net/manual/en/function.session-set-save-handler.php
try
{
echo $data;
echo '<br>';
$expire=time()+$this->getTimeout();
$db=$this->getDbConnection();
$sql="SELECT id FROM {$this->sessionTableName} WHERE id=:id";
if($db->createCommand($sql)->bindValue(':id',$id)->queryScalar()===false)
$sql="INSERT INTO {$this->sessionTableName} (id, data, expire) VALUES (:id, :data, $expire)";
else
$sql="UPDATE {$this->sessionTableName} SET expire=$expire, data=:data WHERE id=:id";
$db->createCommand($sql)->bindValue(':id',$id)->bindValue(':data', base64_encode($data) )->execute();
}
catch(Exception $e)
{
if(YII_DEBUG)
echo $e->getMessage();
// it is too late to log an error message here
return false;
}
return true;
}
Work around: add base64 encode/decode to CDbHttpSession writeSession / readSession
Settings for session in config/main.php:
'session'=>array(
'class'=>'CDbHttpSession',
'connectionID'=>'db',),