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/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Is it possible the change the active_group on the fly? (/thread-26774.html)



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