简体   繁体   中英

A Database Error 1146 in Codeigniter

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?

  1. Note that the user-guide you've linked to is for version 2.2.0 and no longer official, while you're using 3.0.x.
  2. Read the actual user guide here: http://www.codeigniter.com/userguide3/libraries/sessions.html
  3. Don't just tell us that you've read and followed all steps, but actually do it - you haven't created a ci_sessions table in the database. The error message itself tells you this.

Actually you are mixing up both session drivers ie 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');

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM