Switch database dynamically in Codeigniter 3.x |
I need to dynamically switch to another database depending on the domain name. I have a table in database-1 that stores the credentials for the other databases. I have enabled the 'database' library in autoload.php with the credentials of database-1 in database.php. The models should use the already available OTHER database credentials, otherwise fetch the credentials from database-1. However, I'm not sure where to omegle.2yu.co securely store the credentials and how to reconfigure CI to use the fetched credentials instead of the default credentials from database.php. How omeglz echat can I resolve these issues?
$this->load->model('otherdb'); $otherconfig=$this->otherdb->getotherdb(base_url()); $config=array(); if(isset($otherconfig) && !empty($otherconfig)){ $config['hostname'] = $otherconfig->host; $config['username'] = $otherconfig->user; $config['password'] = $otherconfig->pass; $config['database'] = $otherconfig->nameofdb; $config['dbdriver'] = 'mysqli'; $config['dbprefix'] = ''; $config['pconnect'] = FALSE; $config['db_debug'] = TRUE; } $this->load->database($config); //doesnt work, still uses old DB $this->load->model('model1','',$config); //doesnt work, still uses old DB $this->load->model("model2",'',$config); //doesnt work, still uses old DB $this->load->model('model3','',$config); //doesnt work, still uses old DB |
Messages In This Thread |
Switch database dynamically in Codeigniter 3.x - by LansoirThemtq - 03-02-2023, 09:38 PM
|