Zend Framework

Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Zend_Session_SaveHandler_DbTable' Using DB resource

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 1.8.2
  • Fix Version/s: None
  • Component/s: Zend_Application
  • Labels:
    None

Description

I'm trying to use Zend_Applicatoin to load my database then Session. Here is the snippet of the ini file:

phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0

autoloadernamespaces.nexus = "NEXUS_"
autoloadernamespaces.nexus = "APPLICATION_"

includePaths.library = LIBRARY_PATH
includePaths.application = APPLICATION_PATH

bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"

resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = ""
resources.db.params.charset = "utf8"
resources.db.params.dbname = "tbr"
resources.db.isDefaultTableAdapter = true

resources.modules[] = true

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.actionhelperpaths.main = APPLICATION_PATH "/controllers/helpers"
;resources.frontController.baseUrl = "/subdir"
;resources.frontController.plugins.foo = "My_Plugin_Foo"
;resources.frontController.plugins.bar = "My_Plugin_Bar"
resources.frontController.env = APPLICATION_ENV

resources.session.save_path = DATA_PATH "/session"
resources.session.use_only_cookies = true
resources.session.remember_me_seconds = 864000
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable"
resources.session.saveHandler.options.name = "session"
resources.session.saveHandler.options.primary.session_id = "session_id"
resources.session.saveHandler.options.primary.save_path = "save_path"
resources.session.saveHandler.options.primary.name = "name"
resources.session.saveHandler.options.primaryAssignment.sessionId = "sessionId"
resources.session.saveHandler.options.primaryAssignment.sessionSavePath = "sessionSavePath"
resources.session.saveHandler.options.primaryAssignment.sessionName = "sessionName"
resources.session.saveHandler.options.modifiedColumn = "modified"
resources.session.saveHandler.options.dataColumn = "session_data"
resources.session.saveHandler.options.lifetimeColumn = "lifetime"

What happends is when Zend_Application_Resource_Session is loaded via BootstrapAbstract.php _loadPluginResource it is passed to Zend_Application_Resource_ResourceAbstract which passes to its setOptions method which calls Zend_Application_Resource_Session::setSavehandler which loads the table abstract and dies at no adapter because the db resource init function has yet to be run and thus not connected and default adapter not set.

Hope it makes sence Its pretty late here and quite tired. If I'm missing something please point me in the right direction as google didn't solve this issue.

All the best,

Jay

Issue Links

Activity

Hide
julien PAULI added a comment -

This duplicates #ZF-6942

Show
julien PAULI added a comment - This duplicates #ZF-6942
Hide
Jason Brumwell added a comment -

I'm not sure if this is the same, as I was aware of the dependancy on the db resource and did as the documentation stated:

Bootstrap your database first!

If you are configuring the Zend_Session_SaveHandler_DbTable session save handler, you must first configure your database connection for it to work. Do this by either using the Db resource – and make sure the "resources.db" key comes prior to the "resources.session" key – or by writing your own resource that initializes the database, and specifically sets the default Zend_Db_Table adapter.

The bug you linked states:

Using Resource_Session with the DbTable-Savehandler cause an exception, if the Db-Resource is not called before.

but I was unable to get it to work without moving it to the bootstrap _iniDb and initializing the database. I just wanted to ensure that the correct bug is put forward.

Show
Jason Brumwell added a comment - I'm not sure if this is the same, as I was aware of the dependancy on the db resource and did as the documentation stated: Bootstrap your database first! If you are configuring the Zend_Session_SaveHandler_DbTable session save handler, you must first configure your database connection for it to work. Do this by either using the Db resource – and make sure the "resources.db" key comes prior to the "resources.session" key – or by writing your own resource that initializes the database, and specifically sets the default Zend_Db_Table adapter. The bug you linked states: Using Resource_Session with the DbTable-Savehandler cause an exception, if the Db-Resource is not called before. but I was unable to get it to work without moving it to the bootstrap _iniDb and initializing the database. I just wanted to ensure that the correct bug is put forward.
Hide
Adam Weinstock added a comment -

I'm getting this too.

The problem occurs because Zend_Application_Bootstrap_BootstrapAbstract::getPluginResourceNames() calls Zend_Application_Bootstrap_BootstrapAbstract::getPluginResources() which in turn calls Zend_Application_Bootstrap_BootstrapAbstract::_loadPluginResource(). This instantiates but does not execute instances of the registered resource objects, causing Zend_Application_Resource_Session::setSaveHandler() to instantiate an instance of Zend_Db_Table_Abstract before the Db resource is actually executed. Since Zend_Application_Resource_Db doesn't call Zend_Db_Table::setDefaultAdapter() until it's init() method is called, the desired behavior fails.

The simplest solution seems to be to remove the call to getPluginResources() in Zend_Application_Bootstrap_BootstrapAbstract::getPluginResourceNames(). This seems to be working for me, but may cause problems, so another solution may be more desirable. In any case, this bug will definitely cause problems with other resources down the line and should be fixed up.

Show
Adam Weinstock added a comment - I'm getting this too. The problem occurs because Zend_Application_Bootstrap_BootstrapAbstract::getPluginResourceNames() calls Zend_Application_Bootstrap_BootstrapAbstract::getPluginResources() which in turn calls Zend_Application_Bootstrap_BootstrapAbstract::_loadPluginResource(). This instantiates but does not execute instances of the registered resource objects, causing Zend_Application_Resource_Session::setSaveHandler() to instantiate an instance of Zend_Db_Table_Abstract before the Db resource is actually executed. Since Zend_Application_Resource_Db doesn't call Zend_Db_Table::setDefaultAdapter() until it's init() method is called, the desired behavior fails. The simplest solution seems to be to remove the call to getPluginResources() in Zend_Application_Bootstrap_BootstrapAbstract::getPluginResourceNames(). This seems to be working for me, but may cause problems, so another solution may be more desirable. In any case, this bug will definitely cause problems with other resources down the line and should be fixed up.
Hide
Kevin Foster added a comment -

I have the same problem after upgrading from 1.7.8 to 1.9.1. It seems this bug has been recently introduced.

Show
Kevin Foster added a comment - I have the same problem after upgrading from 1.7.8 to 1.9.1. It seems this bug has been recently introduced.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: