Zend_Session-SaveHandler-DbTable.xml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <sect1 id="zend.session.savehandler.dbtable">
  2. <title>Zend_Session_SaveHandler_DbTable</title>
  3. <para>
  4. ההתקנה הבסיסית של Zend_Session_SaveHandler_DbTable חייבת לכלול לפחות 4 עמודות,
  5. המצויינים בקובץ ההגדרות/אובייקט ההגדרות:
  6. primary, אשר הוא המפתח הראשי וכברירת מחדל מוגדר למזהה היחודי אשר בעצם סטרינג באורך 32 תווים;
  7. modified, אשר משמש בתור זמן בפורמט UNIX של התאריך עדכון האחרון;
  8. lifetime, אשר משמש בתור תקופת החיים של ה session (modified + lifetime > time() );
  9. data, אשר משמש בתור המידע אשר נשמר בטבלה.
  10. </para>
  11. <example id="zend.session.savehandler.dbtable.basic">
  12. <title>שימוש בסיסי</title>
  13. <programlisting role="SQL"><![CDATA[
  14. CREATE TABLE `session` (
  15. `id` char(32),
  16. `modified` int,
  17. `lifetime` int,
  18. `data` text,
  19. PRIMARY KEY (`id`)
  20. );
  21. ]]>
  22. </programlisting>
  23. <programlisting role="php"><![CDATA[
  24. //get your database connection ready
  25. $db = Zend_Db::factory('Pdo_Mysql', array(
  26. 'host' =>'example.com',
  27. 'username' => 'dbuser',
  28. 'password' => '******',
  29. 'dbname' => 'dbname'
  30. ));
  31. //you can either set the Zend_Db_Table default adapter
  32. //or you can pass the db connection straight to the save handler $config
  33. Zend_Db_Table_Abstract::setDefaultAdapter($db);
  34. $config = array(
  35. 'name' => 'session',
  36. 'primary' => 'id',
  37. 'modifiedColumn' => 'modified',
  38. 'dataColumn' => 'data',
  39. 'lifetimeColumn' => 'lifetime'
  40. );
  41. //create your Zend_Session_SaveHandler_DbTable and
  42. //set the save handler for Zend_Session
  43. Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
  44. //start your session!
  45. Zend_Session::start();
  46. //now you can use Zend_Session like any other time
  47. ]]>
  48. </programlisting>
  49. </example>
  50. <para>
  51. ניתן גם להשתמש בכמה מפתחות ראשיים לכמה עמודות ב Zend_Session_SaveHandler_DbTable.
  52. </para>
  53. <example id="zend.session.savehandler.dbtable.multi-column-key">
  54. <title>שימוש במפתח ראשי לכמה עמודות</title>
  55. <programlisting role="SQL"><![CDATA[
  56. CREATE TABLE `session` (
  57. `session_id` char(32) NOT NULL,
  58. `save_path` varchar(32) NOT NULL,
  59. `name` varchar(32) NOT NULL DEFAULT '',
  60. `modified` int,
  61. `lifetime` int,
  62. `session_data` text,
  63. PRIMARY KEY (`Session_ID`, `save_path`, `name`)
  64. );
  65. ]]>
  66. </programlisting>
  67. <programlisting role="php"><![CDATA[
  68. //setup your DB connection like before
  69. //NOTE: this config is also passed to Zend_Db_Table so anything specific
  70. //to the table can be put in the config as well
  71. $config = array(
  72. 'name' => 'session', //table name as per Zend_Db_Table
  73. 'primary' => array(
  74. 'session_id', //the sessionID given by PHP
  75. 'save_path', //session.save_path
  76. 'name', //session name
  77. ),
  78. 'primaryAssignment' => array( //you must tell the save handler which columns you
  79. //are using as the primary key. ORDER IS IMPORTANT
  80. 'sessionId', //first column of the primary key is of the sessionID
  81. 'sessionSavePath', //second column of the primary key is the save path
  82. 'sessionName', //third column of the primary key is the session name
  83. ),
  84. 'modifiedColumn' => 'modified', //time the session should expire
  85. 'dataColumn' => 'session_data', //serialized data
  86. 'lifetimeColumn' => 'lifetime', //end of life for a specific record
  87. );
  88. //Tell Zend_Session to use your Save Handler
  89. Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
  90. //start your session
  91. Zend_Session::start();
  92. //use Zend_Session as normal
  93. ]]>
  94. </programlisting>
  95. </example>
  96. </sect1>
  97. <!--
  98. vim:se ts=4 sw=4 et:
  99. -->