一个是默认的,另一个是第二个数据库,我只需要在少数控制器中维护通过系统的订单。这是代码,我的database.php
文件如下:
这是我的配置:
`$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'carbiz',
'dbdriver' => 'mysqli',
'dbprefix' => 'web_',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['abcd'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'sale2',
'dbdriver' => 'mysqli',
'dbprefix' => 'web_',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);`
这是我的控制器
public function __construct()
{
parent::__construct();
$this->load->model('admin_model');
$this->otherdb = $this->load->database('abcd', TRUE);`
}
现在在使用第二个数据库的同一控制器中的一个功能中
function add_scondary()
{
$val=$this->otherdb->select('title')->get('products');
print_r("here");
print_r($val);
}
常量 CI_VERSION = '3.1.7';