Switching databases |
Is it safe to constantly switch between multiple databases using "USE ..." query? For instance,
$this->db->query("USE webinar_" . $webinar_id); ... do some work ... $this->db->query("USE main_db"); ... etc. I wonder is it better to do like this or to maintain several db connections. ![]()
I think its more resource intensive to open a new db connection. I only use multiple connections if there are actually different db servers I'm interfacing with.
(09-03-2015, 09:19 AM)CroNiX Wrote: I think its more resource intensive to open a new db connection. I only use multiple connections if there are actually different db servers I'm interfacing with. Ok. Is there any way to use Active Record for that, so i could get rid of pure SQL? AFAIK in 2.2 there is no special method for switching DB's, but maybe in 3+ exists?
http://www.codeigniter.com/user_guide/da...-databases
PHP Code: $db1 = $this->load->database('group_one', true); or, if the connections are the same and just the database is different... PHP Code: $this->db->db_select('database1'); (09-03-2015, 12:42 PM)mwhitney Wrote: http://www.codeigniter.com/user_guide/da...-databasesgood one
Musheer
http://codesok.com |
Welcome Guest, Not a member yet? Register Sign In |