database error 1054 in codeigniter database error 1054 in codeigniter codeigniter codeigniter

database error 1054 in codeigniter


According to CI manual regarding Sessions the basic format of the ci_sessions table is:

CREATE TABLE IF NOT EXISTS  `ci_sessions` (    session_id varchar(40) DEFAULT '0' NOT NULL,    ip_address varchar(45) DEFAULT '0' NOT NULL,    user_agent varchar(120) NOT NULL,    last_activity int(10) unsigned DEFAULT 0 NOT NULL,    user_data text NOT NULL,    PRIMARY KEY (session_id),    KEY `last_activity_idx` (`last_activity`));

In your php code you're using different fields:

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

So, by altering that code to:

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

Your code should work.


I think the right solution is to check if your DB is correctly created.

According to Documentation for CI 3.0.0 the correct database would be:

    CREATE TABLE IF NOT EXISTS `ci_sessions` (        `id` varchar(40) NOT NULL,        `ip_address` varchar(45) NOT NULL,        `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,        `data` blob NOT NULL,        PRIMARY KEY (id),        KEY `ci_sessions_timestamp` (`timestamp`));

I dont agree on changing CI drivers files


I got the same problem, i already changed...

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

to ->>>>>

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

the problem will exist if i do this in my config.ph

$config['sess_expiration'] = 7200;$config['sess_expire_on_close'] = TRUE;$config['sess_encrypt_cookie'] = TRUE;$config['sess_use_database'] = TRUE;$config['sess_table_name'] = 'ci_sessions';$config['sess_match_ip'] = TRUE;$config['sess_match_useragent'] = TRUE;$config['sess_time_to_update'] = 300;