Welcome Guest, Not a member yet? Register   Sign In
Active Record & Multiple Databases

So I understand you can connect to more then one database doing something like this.
$DB1 = $this->load->database('group_one', TRUE);
$DB2 = $this->load->database('group_two', TRUE);

My problem is I have written a pretty big application using active record and one (default) database connection. So all my quires look like this.


It has come to my attention I need to move half of the database to another database. So I need two connections. So my quires should look something like this.


Now, I know I can do a search and replace and I will if I must, but is there a way to keep the current 'default' database be $this->db and add a second or third connection. So something like this.

$data1 = $this->db->result();

$data2 = $DB->result();

Every time I load the second database connection and assign it to $DB I lose the connection on $this->db.

Sorry this might be a dumb question but the inter-workings of the database class is something I do not understand all that well in CI.

[eluser]CI Coder[/eluser]
Try setting ['pconnect'] = FALSE in your config array for all of them. You will lose the connection to the first database because mysql_pconnect will look for an open connection to the same host with the same user/password and return that instead of opening a new connection. So, if all your databases are on localhost or in general on the same host, you will have that as long as you use pconnect.

I've only had this problem once and that was a while ago. I hope it helps.

Good luck!

Thanks a bunch CI Coder!!! That solved the problem!!!

Theme © iAndrew 2016 - Forum software by © MyBB