Welcome Guest, Not a member yet? Register   Sign In
Peristent connect when using multiple databases with the same login credentials
#1

[eluser]dignick[/eluser]
After a lot of investigation here I have found that if you have two database objects which use the same database login credentials but different databases, and you have persistent connect enabled for both connections, then problems occur when trying to run queries on the database you initialised first.
Example:
Code:
$test1['hostname'] = "mysql.server.com";
$test1['username'] = "user";
$test1['password'] = "pass";
$test1['pconnect'] = TRUE;
$test1['database'] = "test1";

...

$test2 = $test1;
$test2['database'] = "test2";

...

$db1 = $this->load->database($test1, TRUE);
$db2 = $this->load->database($test2, TRUE);
        
// DB2
$db2->set('test', 2);
$db2->where('id', 0);
$db2->update('test2');
        
// DB1
$db1->set('test', 1);
$db1->where('id', 0);
$db1->update('test1');

Because persistent connect will not return a unique connection id, and the database is only selected when the database object is initialised, then when the $db1 object runs a query its trying to run it on 'test2'. See here for some testing of this.

I wrote a solution. While not ideal, it works.




Theme © iAndrew 2016 - Forum software by © MyBB