Welcome Guest, Not a member yet? Register   Sign In
Changing db in the middle of a script
#1

[eluser]Skinnpenal[/eluser]
Hi guys Smile

I have CI autoloading the database library, so when the app starts it connects to database specified in my config/database.php

Now, in the middle of this app, I need to connect to a different database .. replacing the current connection.

How do I do this "the right way"? Smile

I tried doing
Code:
$this->load->database($config);
and supplying a new config, but that does absolutely nothing, as far as I can tell.

EDIT:

I got this to work:
Code:
$this->db->close();
$this->db->initialize($config);
Is that the proper way to do it?

And another question:
I use database based sessions (because of freak_auth), which means that when I connect to this new database, freak_auth no longer has access to the session it created in the beginning of the script. Any ideas how to fix that?
#2

[eluser]Chris Newton[/eluser]
You can connect to multiple databases, without closing one out. See the documentation:

http://ellislab.com/codeigniter/user-gui...cting.html

Bottom of the page.




Theme © iAndrew 2016 - Forum software by © MyBB