时间:2021-07-01 10:21:17 帮助过:17人阅读
?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); //从此处提交配置参数,可以自定义数据库连接,可以有多个数据库的连接,不依靠config项里的单一数据库配置。 //另一处自定义配置数据库连接参数的地方是在调用模块的地方 //$this->load->mode('My_model', '别名',$db_conn); //别名可以无 } } ?>
也可以在./config/database.php 里定义数据库连接数组,在调用$this->load->database('组名');
例:
./config/database.php
$config['my']['hostname'] = 'localhost';
$config['my']['username'] = 'root';
调用:
$this->load->database('my');
http://codeigniter.org.cn/user_guide/database/connecting.html 这是说明地址