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.
Copy codeThe Code is as follows:
<? Php
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 );
}
?>