I am using Codeigniter framework to build a website. I am receiving this error:
Error Number: 1146
Table 'users.ci_sessions' doesn't exist
SELECT `data` FROM `ci_sessions` WHERE `id` = '5e47bcb40c2954bd7329ff3fbcf253007a0563cc'
Filename: libraries/Session/drivers/Session_database_driver.php
Line Number: 166
Here is how session is defined: In config.php:
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_table_name'] = 'ci_sessions';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_driver'] = 'database'; // changed from file
$config['sess_save_path'] = 'ci_sessions'; // table name
//$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_use_database'] = TRUE;
In autoload.php:
$autoload['libraries'] = array('database','session');
I have read https://ellislab.com/codeigniter/user-guide/libraries/sessions.html and followed all steps to properly access the session. Any suggestion on how to fix above error?
Actually you are mixing up both session drivers i.e database
and file
, so if you would like to use file driver read here the official documentation: http://www.codeigniter.com/userguide3/libraries/sessions.html#files-driver
And if you want to use database driver: http://www.codeigniter.com/userguide3/libraries/sessions.html#database-driver
Also i had encounter an strange bug in auto loading libraries.
Please add session
driver before database
driver in autoload array as:
$autoload['libraries'] = array('session','database');
ci_sessions
table in the database. The error message itself tells you this.be careful with these parameters in config.php
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session'; //ci_session don't add 's' in last
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = 'ci_sessions'; //ci_sessions add 's' in last
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;