In fact, this is not difficult, because the CI just started, so it still took some twists and turns. Fortunately, there is a manual. In fact, this is not difficult, because the CI just started, so it still took some twists and turns. Fortunately, there is a manual.
Find the database configuration file and add the connection information of a new database. $ Config [XX].
In the controller,
A) $ this-> xx = $ this-> load-> database ('XX', TRUE) tip: XX indicates the key name of the database information array you configured, it is recommended to set TRUE to return the connection ID and enable the ActionRecord class respectively.
B) then you can use $ this-> xx-> query () in the controller to query the data of another database. The other library does not need to create a modle file.
The code is as follows:
Function _ construct ()
{
Parent: :__ construct ();
$ This-> xx = $ this-> load-> database ('XX', TRUE );
$ This-> load-> model ('default database and table name ');
}
Function index ()
{
// You can use $ this-> xx-> query () to execute the SQL statement of the XX database.
$ This-> xx-> query ($ SQL );
}
?>
The above is the code for using CI to operate multiple databases in php. For more articles, please follow the PHP Chinese network (www.php1.cn )!