CodeIgniter Forums
Is it possible the change the active_group on the fly? - 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: Is it possible the change the active_group on the fly? (/showthread.php?tid=26774)



Is it possible the change the active_group on the fly? - El Forum - 01-22-2010

[eluser]RJ[/eluser]
Hello,

The program I built can work on one of two databases (1.x,2.x); Based on a user selection I want to change the active_group to select the correct database.

I know I can change the db with $db = $this->load->database('xxx');

In doing so I would have to go back and change all my queries I believe ($this->db becomes $db->query); so changing the active_group seems to be the best solution... now is it possible?


Is it possible the change the active_group on the fly? - El Forum - 01-22-2010

[eluser]Colin Williams[/eluser]
Just doing $this->load->database('group_name'); will append it to the Controller like you want. You could do it early on, like in the controller constructor. Just remember not to autoload it in any way


Is it possible the change the active_group on the fly? - El Forum - 01-22-2010

[eluser]RJ[/eluser]
Tried that didn't seem to like it. I ended up doing this:

<code>$this->db = $this->load->database('v8', TRUE);</code>

Seems to work well! Thanks