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);
精彩评论