Reputation: 159
I am using codeigniter and till date I was using cookie based sessions.. but now size of sessions is increased so i need to store them in database..
I have multiple database(more than 3) connected to my application..How can i specifically use ci_sessions table to store sessions?
when i say $config['sess_use_database'] = TRUE; my app goes blank. a plane white page is shown.
That is because From multiple database connections codeigniter is not finding exact database to store sessions..
How can i achieve the same? Thanks
Upvotes: 2
Views: 2953
Reputation: 1870
When the system/libraries/Session.php
is loaded, it also loads a database to use with the sessions, if specified.
// Are we using a database? If so, load it
if ($this->sess_use_database === TRUE AND $this->sess_table_name != '')
{
$this->CI->load->database();
}
This should, in theory load the default database. For some reason, this did not work for me. I had to modify the code to specifically call the default database.
default
database:// Are we using a database? If so, load it
if ($this->sess_use_database === TRUE AND $this->sess_table_name != '')
{
$this->CI->load->database('default', TRUE);
}
If you would like to use a different database, just change default
to the name of the database which you would like to use.
Note: If you load another database before you call session data, you will need to specify your session data again. The session will continue to try and pull from the currently active database.
Upvotes: 3
Reputation: 3587
Looking at the session code from system/libraries/Session.php
, one can see that it uses the default $this->db
to connect to the database for storing sessions.
Try modifying your database groups such that $this->db
works. Alternatively, you can extend the Session.php
such that you can pass it the database group for storing sessions.
Hope this gets you started in the right direction.
Upvotes: 2