Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何更改codeigniter中的默认数据库_Php_Database_Codeigniter - Fatal编程技术网

Php 如何更改codeigniter中的默认数据库

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'

我想更改控制器中的Deafolt数据库,但它没有更改

我正在这样做:

$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);