CodeIgniter Forums
Accessing multiple databases - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Accessing multiple databases (/showthread.php?tid=43383)



Accessing multiple databases - El Forum - 07-09-2011

[eluser]bapobap[/eluser]
Hello all,

I have a CI application, using Active Record, which works well.

I need to use another database for one single part of a model and I've tried using the code to connect to another database as defined in the docs:

Code:
$DB2 = $this->load->database('group_two', TRUE);

This works, however, even if I manually close the connection, the rest of my app from this point in the code forward, which would usually just use the autoloaded database, will try to use the group_two connection instead.

Is there any way to quickly connect to another database, then just revert back to the autoloaded database as normal? I guess I could use regular PHP to do this but I prefer to use AR if I can and I don't want to change my entire application to use $DB1 instead of $this->db just to allow 10 lines of code for $DB2 to work.

Any help would be appreciated!


Accessing multiple databases - El Forum - 07-09-2011

[eluser]bapobap[/eluser]
My bad, pconnect to false fixes it. Not sure if I should keep pconnect to true but oh well!


Accessing multiple databases - El Forum - 07-09-2011

[eluser]Mirge[/eluser]
Saw this thread and was curious, thanks for posting back with your fix!