Zend_Session_SaveHandler_DbTable
ההתקנה הבסיסית של Zend_Session_SaveHandler_DbTable חייבת לכלול לפחות 4 עמודות,
המצויינים בקובץ ההגדרות/אובייקט ההגדרות:
primary, אשר הוא המפתח הראשי וכברירת מחדל מוגדר למזהה היחודי אשר בעצם סטרינג באורך 32 תווים;
modified, אשר משמש בתור זמן בפורמט UNIX של התאריך עדכון האחרון;
lifetime, אשר משמש בתור תקופת החיים של ה session (modified + lifetime > time() );
data, אשר משמש בתור המידע אשר נשמר בטבלה.
שימוש בסיסי
'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
Zend_Db_Table_Abstract::setDefaultAdapter($db);
$config = array(
'name' => 'session',
'primary' => 'id',
'modifiedColumn' => 'modified',
'dataColumn' => 'data',
'lifetimeColumn' => 'lifetime'
);
//create your Zend_Session_SaveHandler_DbTable and
//set the save handler for Zend_Session
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
//start your session!
Zend_Session::start();
//now you can use Zend_Session like any other time
]]>
ניתן גם להשתמש בכמה מפתחות ראשיים לכמה עמודות ב Zend_Session_SaveHandler_DbTable.
שימוש במפתח ראשי לכמה עמודות
'session', //table name as per Zend_Db_Table
'primary' => array(
'session_id', //the sessionID given by PHP
'save_path', //session.save_path
'name', //session name
),
'primaryAssignment' => array( //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
Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
//start your session
Zend_Session::start();
//use Zend_Session as normal
]]>