CodeIgniter Forums

Full Version: Session w/multiple databases ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I want to try using a database with my sessions.
The issue is I have two databases. The default and most oft used database is a MS Sql Server instance on another machine. The webserver also has a local Mysql database running. I want to connect to the local mysql one for session stuff.

To get this to work (using the NOT default database with sessions) I had to edit the Session.php library file.

It seems to work, but is this the right way? (or is there a better way?)

Basically I changed the way that Session.php loads the database:
$this->CI->local_db = $this->CI->load->database('local',TRUE);

The commented out line is the original.

I then did a search/replace from
in the rest of the Session.php file.

Like I said it seems fine, but I don't like editing the core library stuff.

So is there a better way?

paul w

El Forum

[eluser]Randy Casburn[/eluser]
You should really use a separate library file named MY_session or something and place it in your application/libraries directory. This way you can override the native session library without hacking the core library.

Here is a file for you to work with:

I too need to support multiple databases with sessions. If this is something that is important to you, then add a comment to the post above and see if there is other interest in the community.

Maybe someone else is interested too.