![]() |
Switch database dynamically in Codeigniter 3.x - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17) +--- Thread: Switch database dynamically in Codeigniter 3.x (/showthread.php?tid=86982) |
Switch database dynamically in Codeigniter 3.x - LansoirThemtq - 03-02-2023 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 |