Php 如何更改codeigniter中的默认数据库
我想更改控制器中的Deafolt数据库,但它没有更改 我正在这样做:Php 如何更改codeigniter中的默认数据库,php,database,codeigniter,Php,Database,Codeigniter,我想更改控制器中的Deafolt数据库,但它没有更改 我正在这样做: $this->db->close(); $config['default']['database'] = "second"; $this->load->database($config); 试着这样做: 配置: $active_group = 'default'; $db['default']['hostname'] = 'localhost'; $db['default']['username'
$this->db->close();
$config['default']['database'] = "second";
$this->load->database($config);
试着这样做: 配置:
$active_group = 'default';
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'test1';
//Another database connection.
$db['db2']['hostname'] = 'localhost';
$db['db2']['username'] = 'root';
$db['db2']['password'] = '';
$db['db2']['database'] = 'test2';
控制器:
// close the default connection
$this->db->close();
// connect to the other db
$this->db = $this->load->database('db2', true);