Kohana无法读取数据库中的会话数据


Kohana won't read session data in database

几分钟前,我部署了一个新版本的应用程序到阶段实例。尝试登录后,我有以下错误:

Session_Exception [ 1 ]: Error reading session data. [Details: Database_Exception [ ]: ~ MODPATH/database/classes/Kohana/Database/MySQL.php [ 108 ] ]

Stackoverflow充满了这些错误,但是没有可能的答案帮助我。

我的数据库配置文件:

 <?php defined('SYSPATH') OR die('No direct access allowed.');
return array
(
'default' => array
(
    'type'       => 'MySQL',
    'connection' => array(
        /**
         * The following options are available for MySQL:
         *
         * string   hostname     server hostname, or socket
         * string   database     database name
         * string   username     database username
         * string   password     database password
         * boolean  persistent   use persistent connections?
         * array    variables    system variables as "key => value" pairs
         *
         * Ports and sockets may be appended to the hostname.
         */
        'hostname'   => '127.0.0.1',
        'database'   => 'MY_DATABASE',
        'username'   => 'MY_USER',
        'password'   => 'MY_PASS',
        'persistent' => FALSE,
    ),
    'table_prefix' => '',
    'charset'      => 'utf8',
    'caching'      => FALSE,
),
'alternate' => array(
    'type'       => 'PDO',
    'connection' => array(
        /**
         * The following options are available for PDO:
         *
         * string   dsn         Data Source Name
         * string   username    database username
         * string   password    database password
         * boolean  persistent  use persistent connections?
         */
        'dsn'        => 'mysql:host=localhost;dbname=kohana',
        'username'   => 'root',
        'password'   => 'r00tdb',
        'persistent' => FALSE,
    ),
    /**
     * The following extra options are available for PDO:
     *
     * string   identifier  set the escaping identifier
     */
    'table_prefix' => '',
    'charset'      => 'utf8',
    'caching'      => FALSE,
),
);

已经尝试将主机名更改为localhost -没有效果。其他的看起来都很好。数据库连接必须是正确的,因为我在会话表中有一个新条目(因此用户能够读取&(在会话表中写入新的元组)。

应用程序使用会话setter/getter。当应用程序调用会话getter时,getter会尝试设置一个新实例:

/**
 * Session Getter
 * @return tye
 */
public static function getSession($key = null) {
    // Check, if session is given
    if (!isset($_SESSION)) {
        self::$_session = Session::instance();
    }
    if (!empty($key)) {
        return self::$_session->get($key);
    }
    return self::$_session;
}

Session::instance()SYSPATH/classes/Kohana/Session.php [ 54 ] » Kohana_Session_Database->__construct(arguments)

中执行以下代码
 //  Create a new session instance
 Session::$instances[$type] = $session = new $class($config, $id);

参数转储$config:

array(4) (
"group" => string(7) "default"
"table" => string(8) "sessions"
"gc" => integer 500
"columns" => array(3) (
    "session_id" => string(10) "session_id"
    "last_active" => string(11) "last_active"
    "contents" => string(8) "contents"
)
) 

参数转储$id:

NULL

下面的函数会产生错误(从未修改过!):

    /**
     * Select the database
     *
     * @param   string  $database Database
     * @return  void
     */
    protected function _select_db($database)
    {
            if ( ! mysql_select_db($database, $this->_connection))
            {
                    // Unable to select database
                    throw new Database_Exception(':error',
                            array(':error' => mysql_error($this->_connection)),
                            mysql_errno($this->_connection));
            }
            Database_MySQL::$_current_databases[$this->_connection_id] = $database;
    }

应用程序在我的本地系统上运行良好。所以我认为这可能是一个错误在php。ini。这就是为什么我试图设置以下ini_set在我的index.php

    ini_set('session.auto_start', 0);

没有任何成功…

尝试在bootstrap文件中设置默认会话适配器。

Session::$default = 'database';

发生这种情况的原因可能有很多。Kohana没有用自己的泛型异常来掩盖实际的异常。我建议在catch块中临时抛出原始异常,以查看到底发生了什么。

http://kohanaframework.org/3.3/guide-api/Session阅读

在我的例子中,它来自一个关于"mysql"的弃用警告,需要"mysqli"或"pdo"。因为,我忘记将MAMP PHP模式返回到单独的PHP版本。