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

Code for CI to operate multiple databases in php_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:17:41858browse

In fact, 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 to TRUE later, which means returning the connection ID and enabling the ActionRecord class
b) Then in the controller you can use $this->xx->query() to query your other library data. There is no need to create a model file for your other library

Copy the code 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);
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325681.htmlTechArticleActually, this is not a difficult task, because I just started CI, so it still took a lot of trouble. Fortunately there is a manual. Find the database configuration file and add the connection information for a new library. $config...
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