1

Fatal error: Uncaught exception 'Zend_Db_Table_Exception' with message 'No adapter found for Zend_Session_SaveHandler_DbTable' in C:\wamp\www\hol\library\Zend\Db\Table\Abstract.php on line 755 ( ! ) Zend_Db_Table_Exception: No adapter found for Zend_Session_SaveHandler_DbTable in C:\wamp\www\hol\library\Zend\Db\Table\Abstract.php on line 755 Call Stack

Time Memory Function Location 1 0.0005 373664 {main}( ) ..\init.php:0

2 0.0325 2749720 Zend_Session_SaveHandler_DbTable->__construct( ) ..\init.php:40 3 0.0325 2750168 Zend_Db_Table_Abstract->__construct( ) ..\DbTable.php:207 4 0.0325 2750480 Zend_Session_SaveHandler_DbTable->_setup( ) ..\Abstract.php:268 5 0.0325 2750480 Zend_Db_Table_Abstract->_setup( ) ..\DbTable.php:403 6 0.0325 2750480 Zend_Db_Table_Abstract->_setupDatabaseAdapter( ) ..\Abstract.php:739

Code:

//Configuration consumption
$config = new Zend_Config(require 'config.php');

//Database configuration
$db = Zend_Db::factory($config->database->adapter, array(
    'host'     => $config->database->params->host,
    'username' => $config->database->params->username,
    'password' => $config->database->params->password,
    'dbname'   => $config->database->params->dbname
));

$sess_config = array(
    'name'              => 'session',
    'primary'           => array(
        'session_id',
        'save_path',
        'name',
    ),
    'primaryAssignment' => array(
        'sessionId',
        'sessionSavePath',
        'sessionName',
    ),
    'modifiedColumn'    => 'modified',
    'dataColumn'        => 'session_data',
    'lifetimeColumn'    => 'lifetime',
);

Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($sess_config));

//Initialize the session
Zend_Session::start();

config

<?php
// config.php
return array(
    'database' => array(
        'adapter' => 'Pdo_Mysql',
        'params'  => array(
            'host'     => 'localhost',
            'username' => 'root',
            'password' => '',
            'dbname'   => 'hol'
        )
    ),
    'session' => array(
        'name'              => 'session',
        'primary'           => array(
            'session_id',
            'save_path',
            'name',
        ),
        'primaryAssignment' => array(
            'sessionId',
            'sessionSavePath',
            'sessionName',
        ),
        'modifiedColumn'    => 'modified',
        'dataColumn'        => 'session_data',
        'lifetimeColumn'    => 'lifetime'
    )
);

SQL:

CREATE TABLE `session` (
    `session_id` char(32) NOT NULL,
    `save_path` varchar(32) NOT NULL,
    `name` varchar(32) NOT NULL DEFAULT '',
    `modified` int,
    `lifetime` int,
    `session_data` text,
    PRIMARY KEY (`Session_ID`, `save_path`, `name`)
);

2 Answers 2

2

You didn't post the contents of your config.php, but based on the error I suspect you did not specify an adapter (mysql, pdo, etc).

My config file looks something like (yaml):

database:
  adapter: Pdo_Mysql
  params:
    host:     myhost
    dbname:   mydb
    username: myusername
    password: mypassword

According to the Zend API docs, you have to specify the adapter like this:

// Set this before you make the call to setSaveHandler()
Zend_Db_Table_Abstract::setDefaultAdapter($db);

Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($sess_config));
Sign up to request clarification or add additional context in comments.

9 Comments

I added the config file, I do have an adapter I am quite sure
Looks like you may have to add a database section to your $session_config array. The error 'No adapter found for Zend_Session_SaveHandler_DbTable', refers to the array you passed to the Zend_Session_SaveHandler_DbTable class.
I just did, look my comment in the answer below.
Ya you need to be a little more clear about "crashing". What specifically is happening?
"Apache have occured a problem and must close... " window pop up :S just on that particular file when I browse it.
|
1

You either need to call Zend_Db_Table_Abstract::setDefaultAdapter($db) providing the $db object you created in your configuration example, as it appears you don't have a default DB adapter set up given the error, or you need to add the $db object to the $sess_config array so it gets set up as the DB adapter for Zend_Session.

Zend_Session_SaveHandler_DbTable extends Zend_Db_Table_Abstract and any options unknown to Zend_Session_SaveHandler_DbTable (e.g. database configuration options) are then passed to the constructor of Zend_Db_Table_Abstract which sets up the DbTable.

Try this:

$sess_config = array(
    'db'                => $db, // Pass the $db adapter as the 'db' parameter to Zend_Db_Table_Abstract
    'name'              => 'session',
    'primary'           => array(
        'session_id',
        'save_path',
        'name',
    ),
    'primaryAssignment' => array(
        'sessionId',
        'sessionSavePath',
        'sessionName',
    ),
    'modifiedColumn'    => 'modified',
    'dataColumn'        => 'session_data',
    'lifetimeColumn'    => 'lifetime',
);

7 Comments

By some reason my Apache server is crashing when I visit the page... but I can load any other file, like the config.php without problem.
@John Crashing as in a segfault or 500 internal server error?
It says the "program" have crashed, and then I am redirected to: localhost.se/hol/init.php instead of the usual adress localhost/hol/init.php
Does this happen on all pages that use a database connection?
No, just on the particular file init.php, all other files seems fine, when I remove "Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($sess_config));" it works again.. (I have no other file to test, since i just have one database file)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.