Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

php - Codeigniter error session DB

After upgrade Codeigniter to version 3.0 I get error DB after trying call any controller:

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id` = 'd1d384b0ceed0bd72fa210337acc666aab1a04e5'' at line 2

SELECT `data` WHERE `id` = 'd1d384b0ceed0bd72fa210337acc666aab1a04e5'

Filename: libraries/Session/drivers/Session_database_driver.php

When I reload page, I get that again with a other generated hash session. How to fix?

In config.php I set session store: $config['sess_driver'] = 'database';

I looked at file where is a error(line 138):

public function read($session_id)
    {
        if ($this->_get_lock($session_id) !== FALSE)
        {
            // Needed by write() to detect session_regenerate_id() calls
            $this->_session_id = $session_id;

            $this->_db
                ->select('data')
                ->from($this->_config['save_path'])
                ->where('id', $session_id);

            if ($this->_config['match_ip'])
            {
                $this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']);
            }

            if (($result = $this->_db->get()->row()) === NULL) // Line 138
            {
                $this->_fingerprint = md5('');
                return '';
            }

            $this->_fingerprint = md5(rtrim($result->data));
            $this->_row_exists = TRUE;
            return $result->data;
        }

        $this->_fingerprint = md5('');
        return '';
    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had this same problem and it took me a while to find the solution. On the surface, the instructions tell you to just load the session driver and everything is cool, but if you look down in the Database Driver section of the CodeIgniter documentation, you find that you need to configure the $config[‘sess_save_path’] variable in your config.php file. For example:

 $config[‘sess_save_path’] = ‘ci_sessions’

http://www.codeigniter.com/userguide3/libraries/sessions.html#initializing-a-session

Of course, you have to have the ci_sessions table set up in your database as well, but this solved the missing table name for me.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...