Codeigniter - Using Multiple Databases Codeigniter - Using Multiple Databases codeigniter codeigniter

Codeigniter - Using Multiple Databases


There is a bug in codeigniter. Inserting one line into a class will fix the whole thing. Here is the original source: http://koorb.wordpress.com/2007/11/16/codeigniter-connect-to-multiple-databases/

** This fix does not apply to PostgreSQL

Here is a copy just in case that site goes down.

The line number has changed. Here is the bug fix from codeigniter:

start bugfix

Description

all of the database calls go to the same database (last one initialized)

To fix the problem change the simple_query function in /system/database/DB_driver.php:

function simple_query($sql){    if ( ! $this->conn_id)    {        $this->initialize();    }       $this->db_select(); //<-----------------  Added this line    return $this->_execute($sql);}

This completely fixes the problem, so you can do stuff like this in a model

$this->legacy_db = $this->load->database('legacy', true);


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.


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;