Codeigniter - Using Multiple Databases

后端 未结 6 732
甜味超标
甜味超标 2020-11-29 04:01

database.php:

$db[\'default\'][\'hostname\'] = \"192.168.2.104\";
$db[\'default\'][\'username\'] = \"webuser\";
$db[\'default\'][\'password\         


        
6条回答
  •  孤街浪徒
    2020-11-29 04:48

    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);
    

提交回复
热议问题