Home >Backend Development >PHP Tutorial >Code for CI to operate multiple databases in php

Code for CI to operate multiple databases in php

黄舟
黄舟Original
2016-12-17 09:21:351247browse

Actually, this is not a difficult task. Because I just started CI, it still took a lot of trouble. Fortunately there is a manual.

Find the database configuration file and add the connection information of a new library. $config[XX].
In the controller,
  a) $this->xx = $this->load->database('XX', TRUE) tip:XX represents the key name of the database information array you configured. It is recommended to set it later Is TRUE, which means returning the connection ID and enabling the ActionRecord class respectively b) Then in the controller you can use $this->xx->query() to query the data of another library of yours. There is no need to create a model file for your other library

. The code is as follows:

function __construct()
{
parent::__construct();
$this->xx = $ this->load->database('XX', TRUE);
$this->load->model('Default library table name');
}
function index()
{
//Now You can use $this->xx->query() to execute the sql of XX library
$this->xx->query($sql);
}
?>

The above is the CI in php For the content of codes that operate multiple databases, please pay attention to the PHP Chinese website (www.php.cn) for more related articles!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:PHP array study notesNext article:PHP array study notes