Welcome Guest, Not a member yet? Register   Sign In
Can I connect to multiple databases while using the auto connection feature?
#1

[eluser]D_Williams[/eluser]
My script needs to access two separate databases. One will be used much more than the other, so I'd like to have it be the default connection and always initialized. This alone is no problem. I have the details in my database config file and the database library is autoloaded.

Can I still keep it like this and safely connect to another database simultaneously? The user guide gives the example of

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

to be connected to more than one database and then using $DB1 and $DB2 instead of $this->db .

What I would like to do is something like this:
Code:
$secondaryDB = $this->load->database('secondary', TRUE);

$this->db->query('blah blah blah'); // Sends the query to the automatically connected to DB
$secondaryDB->query('blah blah blah'); // Sends the query to the other database

Is that possible without causing problems?
#2

[eluser]Kamarg[/eluser]
That works fine. I have the exact scenario and haven't had any problems connecting/querying both databases.




Theme © iAndrew 2016 - Forum software by © MyBB