Reference http://codeigniter.org.cn/user_guide/database/connecting.html Manual
First, set up the connection information for multiple databases in database.php, named ' Test ' here
$db [' Test '] [' hostname '] = "localhost", $db [' Test '] [' username '] = "root"; $db [' Test '] [' password '] = ""; $db [' Test '] [' Database '] = "database_name"; $db [' Test '] [' dbdriver '] = "MySQL"; $db [' Test '] [' dbprefix '] = ""; $db [' Test '] [' pconnect '] = TRUE; $db [' Test '] [' db_debug '] = false; $db [' Test '] [' cache_on '] = false; $db [' Test '] [' cachedir '] = ""; $db [' Test '] [' Char_ Set '] = "UTF8"; $db [' Test '] [' dbcollat '] = "utf8_general_ci"; $db [' Test '] [' swap_pre '] = ""; $db [' Test '] [' autoinit '] = TRUE ; $db [' Test '] [' stricton '] = FALSE;
Remember to change the configuration of Pconnect to False, the other unchanged
Load Database
$this->db1= $this->load->database (' Default ', TRUE), $this->db2= $this->load->database (' Test ', TRUE);
Calling database functions
$this->db1->get (' News ')->result-array (), $this->db1->where (' name ', ' Test '); $this->db1->get ( ' News ')->result-array ();
This makes it possible to connect multiple databases.
CI connects multiple databases