? 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