have you tried it in a model or the autoload function of codeigniter
I fix the problem changing the DB_driver.php on the framework.
in this function I add "$this->db_select();" and you never loose your connection again when working with 2 databases.
function simple_query($sql) { if ( ! $this->conn_id) { $this->initialize(); }
$this->db_select();
return $this->_execute($sql);
}
Instead of applying the hack as mentioned by Camacho you can also set the 'pconnect'-flag in the database.php file to FALSE for all connections.
See http://codeigniter.com/bug_tracker/bug/2703/ for the issue.
currently, codeigniter cannot connect to multiple database in persisten connection. so, you should turn of the persisten of your connections. you may can do this..
$db['default']['pconnect'] = FALSE;
$db['stats']['pconnect'] = FALSE;
Here is an example of how to connect multiple databases to your codeigniter installation.
http://www.gotphp.com/php/codeigniter-multiple-database-support/5468/
Hi,
You may try modifying function CI_Session() in session.php file.
Replace
$this->CI->load->database();
with this
$this->CI->db1 = $this->CI->load->database('default', TRUE); $this->CI->db2 = $this->CI->load->database('db2', TRUE);
In this way, you need not load 2 dbs in all the model files but shall use them directly using objects.
$this->db1 would be accessing default group db and $this->db2 would be accessing db2 group db. (both db groups should have been defined in database.php)
Sundar