簡體   English   中英

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無效。 其他一切看起來都很好。 數據庫連接必須正確,因為我的會話表中有一個新條目(以便用戶能夠在會話表中讀取和寫入新的元組)。

應用程序使用會話設置器/獲取器。 當應用程序調用會話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)執行以下代碼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中可能是錯誤。 這就是為什么我嘗試在index.php中通過ini_set設置以下內容

    ini_set('session.auto_start', 0);

沒有任何成功..

嘗試在bootstrap文件中設置默認會話適配器。

Session::$default = 'database';

發生這種情況的原因可能有很多。 Kohana無助地掩飾了實際異常及其自身的通用異常。 我建議暫時將原始異常拋出到catch塊中,以查看實際情況。

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

以我為例,它來自有關“ mysql”以及對“ mysqli”或“ pdo”的需求的過時警告。 因為,我忘了將MAMP PHP模式返回到各個PHP版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM