开发者

CodeIgniter's dbutils not recognizing new database connection

开发者 https://www.devze.com 2023-04-08 03:46 出处:网络
Does the Utility Class reconnect to the database defined in your database configuration file when it\'s initialized?

Does the Utility Class reconnect to the database defined in your database configuration file when it's initialized?

The following code is returning databases from the dev database and not prod:

$this->load->database('prod');
$this->load->dbutil();
print_r($this->dbutil->list_databases());

My database configuration file contains:

$db['dev']['hostname'] = 'localhost';
$db['dev']['username'] = 'root';
$db['d开发者_如何学Cev']['password'] = '';
$db['dev']['database'] = 'mydb';
...

$db['prod']['hostname'] = 'prodhost';
$db['prod']['username'] = 'username';
$db['prod']['password'] = 'password';
$db['prod']['database'] = 'myproddb';
...

edit 1: indeed, dbutil appears to be influenced by $active_group variable in the database configuration file. How do I override this for a single function? I thought that was the purpose of $this->load->database('environment'); ... no?


The Utility class uses the database assigned to $this->db to carry out its functions.

The solution was to assign the result of $this->load->database('environment') to $this->db:

$this->db = $this->load->database('environment', TRUE);
0

精彩评论

暂无评论...
验证码 换一张
取 消