ZF-6651: Error within Zend_Session_SaveHandler

Description

After i updated to 1.8.1 i got this error

Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Zend_Session_SaveHandler_DbTable' in /is/htdocs/wp1133477_NBOOWRX8MH/libraries/Zend_1.8.1/Zend/Db/Table/Abstract.php:667 Stack trace:

0 /is/htdocs/wp1133477_NBOOWRX8MH/libraries/Zend_1.8.1/Zend/Db/Table/Abstract.php(652): Zend_Db_Table_Abstract->_setupDatabaseAdapter()

1 /is/htdocs/wp1133477_NBOOWRX8MH/libraries/Zend_1.8.1/Zend/Session/SaveHandler/DbTable.php(401): Zend_Db_Table_Abstract->_setup()

2 /is/htdocs/wp1133477_NBOOWRX8MH/libraries/Zend_1.8.1/Zend/Db/Table/Abstract.php(286): Zend_Session_SaveHandler_DbTable->_setup()

3 /is/htdocs/wp1133477_NBOOWRX8MH/libraries/Zend_1.8.1/Zend/Session/SaveHandler/DbTable.php(205): Zend_Db_Table_Abstract->__construct(Array)

4 /is/htdocs/wp1133477_NBOOWRX8MH/libraries/Zend_1.8.1/Zend/Application/Resource/Session.php(59): Zend_Session_SaveHandler_DbTable->__construct(Array)

5 /is/htdocs/wp1133477_NBOOWRX8MH/libraries/Zend_1.8.1/Zend/Application/Resource/ResourceAbstract.php(96): Zend_Ap in /is/htdocs/wp1133477_NBOOWRX8MH/libraries/Zend_1.8.1/Zend/Db/Table/Abstract.php on line 667

First i thought, i have defined resources.db in my .ini before resources.session, but it's not:

resources.db.isDefaultTableAdapter = true resources.db.adapter = "pdo_mysql" resources.db.params.host = "localhost" resources.db.params.driver_options.1002 = "SET NAMES utf8"

resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable" resources.session.saveHandler.options.name = "session" resources.session.saveHandler.options.primary = "id" resources.session.saveHandler.options.modifiedColumn = "modified" resources.session.saveHandler.options.dataColumn = "data" resources.session.saveHandler.options.lifetimeColumn = "lifetime"

I think, it's because while setOptions() in ResourceAbstract a new SaveHandler instance is created but at this point no DB Adapter is created because this should happen later in the init() calls!

Comments

Set component and auto reassign

Anyone on this Issue?

My proposition to solve this problem (easy to implement). Please download Session.patch from attachment.

Great! I will test it tonight and post the results.

I tested my patch and I found some errors in my code... I'm sorry for this problem. Now, I fixed my code and upload file "Session.php" with "Zend_Application_Resource_Session" class. I think It should work very well. Test it, please!

PS: Sorry for my English

Works -- with 1.8.2 as background now -- for me, thanks! If i run in other troubles with your code i will post it here.

Ähm, 1.8.4 out and issue still exists :( But i copied the above file and it works like a charm, so please add it for next release!

Hi! Firstly sorry for my English)) I also have these problems. I think this is patch, is wrong solution.

My Solution

// application/bootstrap.php protected function _initDatabase() { $this->bootstrap('db'); $db = $this->getResource('db'); }

protected function _initSessionStart() { $this->bootstrap('session'); $session = $this->getPluginResource('session'); $session->init(); Zend_Session::start();

}

Config: // application/configs/application.ini resources.session.save_path = APPLICATION_PATH "/../data/session" resources.session.name = "Test" resources.session.use_only_cookies = true resources.session.remember_me_seconds = 1800

resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable" resources.session.saveHandler.options.name = "session"

resources.session.saveHandler.options.primary[] = "session_id" resources.session.saveHandler.options.primary[] = "save_path" resources.session.saveHandler.options.primary[] = "name"

resources.session.saveHandler.options.primaryAssignment[] = "sessionId" resources.session.saveHandler.options.primaryAssignment[] = "sessionSavePath" resources.session.saveHandler.options.primaryAssignment[] = "sessionName"

resources.session.saveHandler.options.modifiedColumn = "modified" resources.session.saveHandler.options.dataColumn = "session_data"

resources.session.saveHandler.options.lifetimeColumn = "lifetime"

Sorry for few words.

Yes, Session.patch is bad solution, but I wrote about this above. Session.php is correct.

Your Session.php is correct and work, but i think this is not "Error within Zend_Session_SaveHandler", just we wrong use this resource. Thank you!

P.S And i think we no need modify Zend_Application_Resource_Session.

I understand what you mean :) Thanks!

Best regards

Hmm... using 1.9.0 RC1 and issue still present.

Session.php from above works with 1.9.0 RC1... so im using it for now... again.

Updated to 1.9.0 issue present Session.php from above still working great

Sorry but i don't understand why you just can't include this patch for now. If there is a better way than just include it now and do the better work later. This issue could be solved as of 1.8.2 now.

It seems like the elegant solution here is to defer instantiation of the Zend_Session_SaveHandler_DbTable until Zend_Application_Resource_Session->init() since Zend_Application_Resource_Db->init() is where the adapter is created and set as default. The instructions are already clear to order the configuration options a certain way and the application plugin system maintains that order properly. All that is needed is to sync the creation of dependent/shared resources into the same method across plugins. In this case, they are out of sync with one being created in init and another being created in the setSaveHandler method.

I will attach a changed file outlining my concept. Perhaps someone can expand on it to make it meet code standards (which I am not familiar with).

Zend_Application_Resource_Session modifications to defer instantiation of savehandler until init()

Ahem, once again:

Still not fixed in 1.9.2, while width above files it's working great.

I think this correction is important because it will use only three lines for the bootstrap minimum ! The must !

This is a duplicate!

No, ZF-6651 is not a duplicate, but ZF-6942 it is!