Zend_Session_SaveHandler_DbTable
The basic setup for Zend_Session_SaveHandler_DbTable must at least
have four columns, denoted in the config array or Zend_Config object:
primary, which is the primary key and defaults to just the session
id which by default is a string of length 32;
modified, which is the unix timestamp of the last modified date;
lifetime, which is the lifetime of the session
(modified + lifetime > time(););
and data, which is the serialized data stored in the session
span style="color: #ff0000;">`session` (
`id` char(32),
`modified``lifetime``data``id`)
);
//get your database connection ready
'Pdo_Mysql''host' =>'example.com',
'username' => 'dbuser',
'password' => '******',
'dbname' => 'dbname'
));
//you can either set the Zend_Db_Table default adapter
//or you can pass the db connection straight to the save handler $config
'name' => 'session',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime'
);
//create your Zend_Session_SaveHandler_DbTable and
//set the save handler for Zend_Session
//start your session!
//now you can use Zend_Session like any other time
You can also use Multiple Columns in your primary key for
Zend_Session_SaveHandler_DbTable.
Example #2 Using a Multi-Column Primary Key
span style="color: #ff0000;">`session` (
`session_id``save_path``name`'',
`modified``lifetime``session_data``Session_ID`, `save_path`, `name`)
);
//setup your DB connection like before
//NOTE: this config is also passed to Zend_Db_Table so anything specific
//to the table can be put in the config as well
'name' => 'session', //table name as per Zend_Db_Table
'primary''session_id', //the sessionID given by PHP
'save_path', //session.save_path
'name', //session name
),
'primaryAssignment'//you must tell the save handler which columns you
//are using as the primary key. ORDER IS IMPORTANT
'sessionId', //first column of the primary key is of the sessionID
'sessionSavePath', //second column of the primary key is the save path
'sessionName', //third column of the primary key is the session name
),
'modifiedColumn' => 'modified', //time the session should expire
'dataColumn' => 'session_data', //serialized data
'lifetimeColumn' => 'lifetime', //end of life for a specific record
);
//Tell Zend_Session to use your Save Handler
//start your session
//use Zend_Session as normal
|
|