【问题标题】:Database Error while updating the ci_session? I am using mulitiple Database?更新 ci_session 时出现数据库错误?我正在使用多个数据库?
【发布时间】:2016-07-14 05:48:34
【问题描述】:

错误号:1146

buz85ftp_buzoonga2.ci_sessions 不存在

UPDATE `ci_sessions` SET `last_activity` = 1468474888, `user_data` = 'a:11:{s:9:\"user_data\";s:0:\"\";s:6:\"userid\";s:3:\"670\";s:5:\"phone\";s:10:\"9956451235\";s:7:\"emailid\";s:15:\"tester@test.com\";s:4:\"name\";s:6:\"Tester\";s:8:\"usertype\";s:1:\"1\";s:16:\"user_country_ref\";s:3:\"673\";s:12:\"user_country\";s:1:\"0\";s:9:\"time_zone\";s:12:\"Asia/Kolkata\";s:14:\"user_logged_in\";b:1;s:17:\"flash:new:success\";s:56:\"

消息已删除

\";}' WHERE session_id = 'f171da0c9be6fa5eb8d32905c8e1251b'

文件名:libraries/Session.php

行号:288

function sess_write()
    {
        // Are we saving custom data to the DB?  If not, all we do is update the cookie
        if ($this->sess_use_database === FALSE)
        {
            $this->_set_cookie();
            return;
        }

        // set the custom userdata, the session data we will set in a second
        $custom_userdata = $this->userdata;
        $cookie_userdata = array();

        // Before continuing, we need to determine if there is any custom data to deal with.
        // Let's determine this by removing the default indexes to see if there's anything left in the array
        // and set the session data while we're at it
        foreach (array('session_id','ip_address','user_agent','last_activity') as $val)
        {
            unset($custom_userdata[$val]);
            $cookie_userdata[$val] = $this->userdata[$val];
        }

        // Did we find any custom data?  If not, we turn the empty array into a string
        // since there's no reason to serialize and store an empty array in the DB
        if (count($custom_userdata) === 0)
        {
            $custom_userdata = '';
        }
        else
        {
            // Serialize the custom data array so we can store it
            $custom_userdata = $this->_serialize($custom_userdata);
        }
        // Run the update query
        $this->CI->db->where('session_id', $this->userdata['session_id']);
        $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata));

        // Write the cookie.  Notice that we manually pass the cookie data array to the
        // _set_cookie() function. Normally that function will store $this->userdata, but
        // in this case that array contains custom data, which we do not want in the cookie.
        $this->_set_cookie($cookie_userdata);
    }

【问题讨论】:

  • 删除记录时出现此错误。数据正在被删除,但我遇到了这个错误?
  • buz85ftp_buzoonga2 数据库不包含 ci_sessions 表。您需要手动创建表。您可以在文档的database driver 部分阅读更多详细信息。
  • ci_sessions 存在于 buz85ftp_buzoonga1 数据库中。我要切换数据库

标签: php codeigniter session multiple-databases


【解决方案1】:

创建一个名为ci_sessions 的表,然后重试

【讨论】:

  • ci_sessions 存在于 buz85ftp_buzoonga1 数据库中。我想切换数据库:(
  • buz85ftp_buzoonga1 应该是您的默认数据库,因此 CI 将能够通过 $this->db 访问它。要访问另一个数据库,您可以创建一个像 $DB1 = $this->load->database('group_one', TRUE); 这样的新连接。此外,您可以像这样使用现有的连接和切换数据库$this->db->db_select('<your database name>');
【解决方案2】:
 $this->CI->load->database('databasename', TRUE);

【讨论】:

  • 我认为这不是一个好的回答方式。只拍代码,不做任何格式化,不做任何解释
猜你喜欢
  • 2020-04-02
  • 1970-01-01
  • 1970-01-01
  • 2017-01-22
  • 2017-09-08
  • 2021-07-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-20
相关资源
最近更新 更多