CI framework custom database connection Configuration

Source: Internet
Author: User
? Detail {publicfunction _ construct () {parent ::__ construct (); $ db_conn [hostname] localhost; $ db_conn [username] root; $ db_conn [password] nagiosxi; $ db_conn [database] web; $ db_conn [dbdriver] mysql; $ d

? Phpclass My_model extends CI_Model {public function _ construct () {parent ::__ construct (); $ db_conn ['hostname'] = localhost; $ db_conn ['username'] = root; $ db_conn ['Password'] = nagiosxi; $ db_conn ['database'] = web; $ db_conn ['dbdriver '] = mysql; $ d

 Load-> database ($ db_conn); // submit configuration parameters from here. You can customize database connections and connect multiple databases, it does not rely on the single database configuration in the config item. // Another custom configuration of database connection parameters is in the calling module. // $ this-> load-> mode ('My _ model', 'Alias ', $ db_conn); // alias can be none}?>

You can also define the database connection array in./config/database. php, and call $ this-> load-> database ('group name ');

Example:

./Config/database. php

$ Config ['my'] ['hostname'] = 'localhost ';

$ Config ['my'] ['username'] = 'root ';

Call:

$ This-> load-> database ('My ');

Http://codeigniter.org.cn/user_guide/database/connecting.html this is the description address

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: info-contact@alibabacloud.com 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.