Code for CI to operate multiple databases in php

黄舟
Release: 2023-03-03 14:42:01
Original
1207 people have browsed it

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!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template