ZF-8636: Zend_Session with saveHandler db and Multi-Column Primary Key

Issue Type: Bug Created: 2009-12-26T18:13:13.000+0000 Last Updated: 2012-02-24T01:56:46.000+0000 Status: Resolved Fix version(s): - 1.11.0 (02/Nov/10)

Reporter: Van Belle Jonathan (grummfy) Assignee: Ramon Henrique Ornelas (ramon) Tags: - Zend_Session

Related issues: - ZF-6868



Hello, like explained there :… and there…

When I'm using the multi-column primary key I have a problem : {quote}
Fatal error: Uncaught exception 'Zend_Session_Exception' with message 'Zend_Session::start() - ..../library/Zend/Db/Table/Abstract.php(Line:900): Error #8 Undefined offset: 1 Array ..../library/Zend/Db/Table/Abstract.php(Line:900): Error #8 Undefined offset: 1 Array ..../library/Zend/Session/SaveHandler/DbTable.php(Line:528): Error #8 Undefined index: session_id Array ..../library/Zend/Session/SaveHandler/DbTable.php(Line:539): Error #8 Undefined index: session_id Array ..../library/Zend/Session/SaveHandler/DbTable.php(Line:528): Error #8 Undefined index: save_path Array ..../library/Zend/Session/SaveHandler/DbTable.php(Line:539): Err in ..../library/Zend/Session.php on line 493

When I do the save with a PHP array of config, the problem doesn't exist. When I convert the ini config in an array with ->toArray(); I find some associative key that were not needed and make the session bugged. " To make this working I implements in the start of application (Zend_Application) this "anti-bug solution", it's uggly but it's a kind of solution while it will be fixed :

<pre class="highlight">
            if (isset($options['resources']['session']['saveHandler']['options']['primaryAssignment']))
                $tmp = $options['resources']['session']['saveHandler']['options']['primary'];
                foreach ($tmp as $v)
                    $options['resources']['session']['saveHandler']['options']['primary'][] = $v;
                $tmp = $options['resources']['session']['saveHandler']['options']['primaryAssignment'];
                foreach ($tmp as $v)
                    $options['resources']['session']['saveHandler']['options']['primaryAssignment'][] = $v;

I take the database structure from the manual :

<pre class="highlight">
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`)

And used an ini file to load all config :

<pre class="highlight">
resources.db.adapter = "Pdo_Mysql" = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "root"
resources.db.params.dbname = "biblio"
resources.db.params.date_format = "YYYY-MM-ddTHH:mm:ss"
resources.db.isDefaultTableAdapter = true

resources.session.save_path = APPLICATION_PATH "/../data/session"
resources.session.use_only_cookies = true
resources.session.remember_me_seconds = 864000
resources.session.saveHandler.class = "Zend_Session_SaveHandler_DbTable" = "session"
resources.session.saveHandler.options.primary.session_id = "session_id"
resources.session.saveHandler.options.primary.save_path = "save_path" = "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"

When I'm boostrap I load db first :

<pre class="highlight">
    protected function _initDb()
        $config = new Zend_Config($this->getOptions());
            $db = Zend_Db::factory($config->resources->db);
        catch (Exception $e)
            exit( $e->getMessage() );

        // on save la connexion
        Zend_Registry::set( 'db', $db );

        return $db;

    protected function _initSession()

I used : * mysql 5.1.37 * php 5.2.10

If you need more information ask!


Posted by Nikolay Mogulev (katalonec) on 2010-04-13T07:30:54.000+0000

other temp solution resources.session.saveHandler.options.primary.0 = "session_id" resources.session.saveHandler.options.primary.1 = "save_path" resources.session.saveHandler.options.primary.2 = "name" resources.session.saveHandler.options.primaryAssignment.0 = "sessionId" resources.session.saveHandler.options.primaryAssignment.1 = "sessionSavePath" resources.session.saveHandler.options.primaryAssignment.2 = "sessionName"

Posted by Christiaan Kras (htbaa) on 2010-04-23T00:44:12.000+0000

@Nikolay Mogulev: Thanks, your solution seems to solve this. This is also present in ZF-1.10.1.

Posted by Ramon Henrique Ornelas (ramon) on 2010-04-23T12:45:44.000+0000

This is a problem in documentation Zend_Application_Resource_Session.

Exists several reported with the same problem ZF-6868, ZF-7000 and ZF-9599.

Posted by Marcus Stöhr (marcus.stoehr) on 2010-05-17T03:00:48.000+0000

When using the obove fix, the following exception is being thrown:

Fatal error: Exception thrown without a stack frame in Unknown on line 0

Posted by Ramon Henrique Ornelas (ramon) on 2010-10-20T10:06:09.000+0000

Fixed with r23177

Posted by Fernando Soto (ferso) on 2010-12-01T13:42:55.000+0000

I find my error with this, my problem is the fields in the database aren't primary key, is need for this configuration, You need add to primary key session_id, save_path, name fields

Posted by Ivo van Beek ( on 2012-02-18T17:50:25.000+0000

Despite the message that this issue is resolved in version 1.11.0, I recently downloaded version 1.11.11 and I'm experiencing the same problem under the exact same circumstances.

The solution of Nikolay Mogulev works.

Posted by Ramon Henrique Ornelas (ramon) on 2012-02-24T01:56:46.000+0000

This is problem of documentation just check to see that this was been corrected ;). See…

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.