-
Notifications
You must be signed in to change notification settings - Fork 7.6k
ci session specific database
I made some improvements to the session library so you can use a specific database. The reason for this arrangement is that in my development I'm managing multiple databases (more than two), and when you change a driver model, should change the name of the connection in the model, so it does not affect the session CI. It is a simple but effective change. I hope you take advantage.
You must to create a library called MY_Session.php with the following changes: [code] class MY_Session extends CI_Session{ [/code] add two variables: $database_name and oDb. $database_name is the database name and oDb is the object database [code] var $CI; var $now; var $database_name = ''; //database name var $oDb ; [/code] In the constructor MY_Session change the following lines: [code] // Are we using a database? If so, load it if ($this->sess_use_database === TRUE AND $this->sess_table_name != '') { $this->CI->load->database(); } [/code] by [code] // Are we using a database? If so, load it if ($this->sess_use_database === TRUE AND $this->sess_table_name != '') { $this->oDb = $this->CI->load->database($this->database_name,TRUE); } [/code] Then change all the lines when are making database connection whith $this->oDb: [code] $this->CI->db->where('session_id', $session['session_id']); [/code] by [code] $this->oDb->where('session_id', $session['session_id']); [/code] To specify the database, add the following line in the file config.php: [code] $config['database_name'] = 'database_name'; [/code] This specify the group name from the file database.php
The library and functions works as usual. Also, you can disable de database, if you want.
The file my_session.php is attached.