Basically, I am facing the same problem as the poster in this issue . My database is initialized correctly. I tried to initialize both the database and the SaveHandler session in application.ini and in Bootstrap . The same result no matter how I do it.
Here is what application.ini initialization looks like:
resources.db.adapter = "pdo_mysql" resources.db.params.host = "localhost" resources.db.params.username = "uname" resources.db.params.password = "******" resources.db.params.dbname = "dbname" resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable" resources.session.saveHandler.options.name = "sessions" resources.session.saveHandler.options.primary = "sessionID" resources.session.saveHandler.options.modifiedColumn = "lastModifiedTime" resources.session.saveHandler.options.dataColumn = "data" resources.session.saveHandler.options.lifetimeColumn = "lifetime"
And here is what Bootstrap initialization looked like:
protected function _initSession() { $db = Zend_Db::factory('Pdo_Mysql', array( 'host' =>'localhost', 'username' => 'uname', 'password' => '******', 'dbname' => 'dbname' )); Zend_Db_Table_Abstract::setDefaultAdapter($db); $sessionConfig = array( 'name' => 'sessions', 'primary' => 'sessionID', 'modifiedColumn' => 'lastModifiedTime', 'dataColumn' => 'data', 'lifetimeColumn' => 'lifetime' ); $saveHandler = new Zend_Session_SaveHandler_DbTable($sessionConfig); Zend_Session::setSaveHandler($saveHandler); Zend_Session::start(); }
The session table of my session is defined as follows:
create table sesssions ( sessionID char(32) primary key not null, lastModifiedTime timestamp, lifetime timestamp, data text ) engine=innodb;
I have a test action that validates this through a very simple form of a single field that simply uploads its contents to the session. The action is as follows:
public function addAction() { $namespace = new Zend_Session_Namespace(); $form = new Application_Form_AddToSession(); $request = $this->getRequest(); if ($request->isPost()) { if ($form->isValid($request->getPost())) { $namespace->content = $request->getParam('toAdd'); } } $this->view->form = $form; }
The form is used here:
class Application_Form_AddToSession extends Zend_Form { public function init() { $this->setMethod('post'); $this->addElement('text', 'toAdd', array( 'filters' => array('StringTrim', 'StringToLower'), 'validators' => array( array('StringLength', false, array(0, 256)), ), 'required' => true, 'label' => 'Add:', )); $this->addElement('submit', 'add', array( 'required' => false, 'ignore' => true, 'label' => 'Add', )); } }
The view simply shows the shape.
To check if the value really got into the session, I use the index action. This is an index action:
public function indexAction() { $namespace = new Zend_Session_Namespace(); echo 'Content: '.$namespace->content.'<br>'; echo '<pre>'; print_r($_SESSION); echo '</pre>'; }
Now. If I don't have a session save configured to use Zend_Session_SaveHandler_DbTable , i.e. If I donβt have a session setup at all, then this works fine. I enter the value in the form field, go to the index action and return it back. The session works exactly as intended.
If I have Zend_Session_SaveHandler_DbTable configured in either application.ini or Bootstrap, then when I enter the value in the test field and go to the index action, the value did not pass. There is a row in my database table with the correct sessionID , and sessionID matches the cookie in my browser. But there is no other information in the database. data is NULL and both TIMESTAMP fields are nullified.
I did not have enough strength to try. I had a Mysql table as a regular table and an InnoDB table. I tried every permutation of the database and session configurations that I can come up with, including providing db in the configuration array and initializing in Bootstrap and the other in .ini . I browsed the web pages and StackOverflow for tips. I saw other people posting similar issues, but none of the answers I found worked. What haven't I done? What have I messed up? How can I make it work?