Guest User

Untitled

a guest
Apr 10th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. CREATE TABLE `Sessions` (
  2. `id` varchar(32) NOT NULL,
  3. `modified` int(11) default NULL,
  4. `lifetime` int(11) default NULL,
  5. `data` text,
  6. PRIMARY KEY (`id`)
  7. ) ENGINE=InnoDB
  8.  
  9. $sessionConfig = array(
  10. 'name' => 'Sessions', //table name as per Zend_Db_Table
  11. 'primary' => 'id', //the sessionID given by php
  12. 'modifiedColumn' => 'modified', //time the session should expire
  13. 'dataColumn' => 'data', //serialized data
  14. 'lifetimeColumn' => 'lifetime' //end of life for a specific record
  15. );
  16. $saveHandler = new Zend_Session_SaveHandler_DbTable($sessionConfig);
  17. //cookie persist for 30 days
  18. Zend_Session::rememberMe($seconds = (60 * 60 * 24 * 30));
  19.  
  20. //make the session persist for 30 days
  21. $saveHandler->setLifetime($seconds)
  22. ->setOverrideLifetime(true);
  23. //similarly,
  24. //$saveHandler->setLifetime($seconds, true);
  25. Zend_Session::setSaveHandler($saveHandler);
  26. Zend_Session::start();
  27.  
  28. resources.db.isDefaultTableAdapter = true
  29. resources.db.adapter = "pdo_mysql"
  30. resources.db.params.host = "localhost"
  31. resources.db.params.dbname = "dbname"
  32. resources.db.params.username = "username"
  33. resources.db.params.password = "password"
  34.  
  35. protected function _initSession() {
  36. $resource = $this->getPluginResource('db');
  37. $dbAdapter = $db = $resource->getDbAdapter();
  38. Zend_Registry::set("db", $dbAdapter);
  39. Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);
  40. $config = array(
  41. 'name' => 'session',
  42. 'primary' => 'id',
  43. 'modifiedColumn' => 'modified',
  44. 'dataColumn' => 'data',
  45. 'lifetimeColumn' => 'lifetime',
  46. 'db' => $dbAdapter
  47. );
  48.  
  49. Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
  50. Zend_Session::start();
  51. }
  52.  
  53. DROP TABLE IF EXISTS `session`;
  54.  
  55.  
  56. CREATE TABLE `session` (
  57.  
  58. `id` char(32) NOT NULL DEFAULT '',
  59.  
  60. `modified` int(11) DEFAULT NULL,
  61.  
  62. `lifetime` int(11) DEFAULT NULL,
  63.  
  64. `data` text,
  65.  
  66. PRIMARY KEY (`id`)
  67.  
  68. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Add Comment
Please, Sign In to add comment