If you have several database connection groups defined in config / database.php, for example:
$db['dbname']['hostname'] = "localhost"; $db['dbname']['username'] = "root"; $db['dbname']['password'] = "root"; $db['dbname']['database'] = "web_dbname"; $db['dbname_readonly']['hostname'] = "localhost"; $db['dbname_readonly']['username'] = "root"; $db['dbname_readonly']['password'] = "root"; $db['dbname_readonly']['database'] = "web_dbname_readonly";
If you want to use the connection parameters of any particular db in the controller or model:
$db = $this->load->database('dbname');
If you want to use in the helper or library:
$ci = &get_instance(); $db = $ci->load->database('dbname');
Connection parameters will be available in the form of $ db-> hostname, $ db-> username, etc.
s1d
source share