Code for executing CI Operations on multiple databases in php

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.