tags:

views:

2586

answers:

6
A: 

have you tried it in a model or the autoload function of codeigniter

http://www.gotphp.com/php/codeigniter-multiple-database-support/
A: 

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);
}
Pedro
+3  A: 

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.

christian studer
A: 

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;

syabac
A: 

Here is an example of how to connect multiple databases to your codeigniter installation.

http://www.gotphp.com/php/codeigniter-multiple-database-support/5468/

Michael
A: 

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

Sundar