【问题标题】:Kohana won't read session data in databaseKohana 不会读取数据库中的会话数据
【发布时间】:2014-07-28 06:47:53
【问题描述】:

几分钟前,我部署了一个新版本的应用程序来暂存实例。尝试登录后出现以下错误:

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 - 无效。其他一切看起来都很好。 数据库连接必须正确,因为我的会话表中有一个新条目(因此用户能够在会话表中读取和写入新元组)。

应用程序使用会话设置器/获取器。当应用程序调用会话 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-&gt;__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 中的错误。这就是为什么我试图在我的 index.php 中通过ini_set 设置以下内容

    ini_set('session.auto_start', 0);

没有任何成功..

【问题讨论】:

    标签: php session kohana


    【解决方案1】:

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

    Session::$default = 'database';
    

    【讨论】:

      【解决方案2】:

      发生这种情况的原因可能有很多。 Kohana 用它自己的通用异常来掩饰实际异常,这无济于事。我建议暂时在 catch 块中抛出原始异常,看看到底发生了什么。

      http://kohanaframework.org/3.3/guide-api/Session#read

      在我的情况下,它来自关于“mysql”的弃用警告以及对“mysqli”或“pdo”的需求。因为,我忘记将我的 MAMP PHP 模式返回到单个 PHP 版本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-22
        • 1970-01-01
        • 1970-01-01
        • 2011-08-27
        • 1970-01-01
        相关资源
        最近更新 更多