error in zend session database for php7

后端 未结 3 1009
半阙折子戏
半阙折子戏 2021-01-06 13:14

My application need to use database instead of file for the session management. My Application is based on Zend Framework

相关标签:
3条回答
  • 2021-01-06 13:29

    The issue is written here: https://github.com/zendframework/zf1/issues/665#issue-127528467

    Since an update that returns 0 but doesn't throw an exception was still a successful query with no error

    Hence the function write will return false instead of true, and PHP 7.0 requires a true result.

    You can fix this by changing, in Zend/Session/SaveHandler/DbTable.php:

    if ($this->update($data, $this->_getPrimary($id, self::PRIMARY_TYPE_WHERECLAUSE))) {
    

    To:

    if (is_int($this->update($data, $this->_getPrimary($id, self::PRIMARY_TYPE_WHERECLAUSE)))) {
    

    Or you can also remove the if, turn it into an instruction, and keep the $return = true;. Because on error, the query should raise an Exception, so any update() without Exception is good.

    0 讨论(0)
  • 2021-01-06 13:31

    In addition to edigus answer here is such a simple implementation of the extended save handler:

    <?php
    
    require_once 'Zend/Session/SaveHandler/DbTable.php';
    
    // NOTE: To fix an issue with Zend_Session_SaveHandler_DbTable on PHP 7 this class extends it and overrides the write
    // method to simply always return true.
    //
    // See: https://stackoverflow.com/a/44985594/1510754
    // See: https://github.com/zendframework/zf1/issues/665
    // See: https://github.com/zendframework/zf1/pull/654
    
    class My_Session_SaveHandler_DbTable extends Zend_Session_SaveHandler_DbTable
    {
    
        public function write($id, $data)
        {
            parent::write($id, $data);
            return true;
        }
    
    }
    
    0 讨论(0)
  • 2021-01-06 13:39

    On September 2016, Zend Framework 1 is reached EOL (end-of-life). This means it will not be improved anymore. The codebase is too old to work well with PHP 7.

    Anyway, you have at least two option:

    1. Downgrade to or run in parallel PHP 5.6 on your server to support ancient ZF1 app.
    2. Write your own session save handler by extending the DbTable handler as suggested here.
    0 讨论(0)
提交回复
热议问题