Working on upgrade to CodeIgniter 3, and encountering some issues with the Session class.
We are configured for storing the session in the database. We have set up the proper ci_sessions table and have this in Config.php:
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 600;
$config['sess_save_path'] = 'ci_sessions';
Trying to store session data with $this->session->set_userdata($data);
With the above we get an error indicating CI is not reading the table name from the "sess_save_path" variable:
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 'SET
last_activity= 1437070556,user_data= 'a:14:{s:9:\\"user_data\\";s:0:\\"\' at line 1UPDATE SET
last_activity= 1437070556,
As you can see the table name is missing between UPDATE and SET
To fix this, I went into Config.php and added the old deprecated method of setting the table name that you aren't supposed to use anymore:
$config['sess_table_name'] = 'ci_sessions';
This works better, but I get a new error:
A Database Error Occurred
Error Number: 1054
Unknown column 'session_id' in 'where clause'
UPDATE
ci_sessionsSETlast_activity= 1437075587,user_data= 'a:14:{ [SESSION DATA REMOVED FROM EXAMPLE] }'WHERE
session_id= '636c6c7389342a7a21111e3e2c3c3f03'Filename: libraries/Session.php
Line Number: 306
What is going on and how do I fix it? Why doesn't $config['sess_save_path'] = 'ci_sessions'; work? What's the deal with the session_id field?
EDIT:
After more testing, I conclude:
$config['sess_save_path'] = 'ci_sessions'; doesn't work
$this->session->set_userdata($data); doesn't work
$this->session->set_userdata('name', $data); doesn't work
$_SESSION['name'] = $data works
Is the CI3 documentation horribly inaccurate, or is something else wrong?
EDIT 2:
New additional problem:
$this->load->library('session');
$data = $_SESSION['data'];
throws Undefined variable: _SESSION. My initial impression is that, in any given function, I have to write to $_SESSION before I can read from $_SESSION
DESC ci_sessions? It is trying to run the query but telling you no such columnsession_idexists which it needs for its session storage. Does not sound like the session table is properly defined. - drew010session_id. That probably means the session code being used is not using the latest CI3 session library. If you look at the code of CI2 session it usessession_id, CI3 sessions usesid, so the library code being run is CodeIgniter2 not 3 hence the sql error. - drew010