![]() |
Configure database config from function - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Configure database config from function (/showthread.php?tid=64519) |
Configure database config from function - vertisan - 02-29-2016 Hi! Is possible to set database config from normal form? Normal config has this option - ok, but now I need to set database config (hostname, user, password, etc.) RE: Configure database config from function - keulu - 02-29-2016 yes you can in your database config file add as many configuration groups as the numbers of your databases: PHP Code: $db['a']['hostname'] = 'localhost'; then on your model initialize a class variable: PHP Code: private $db_b; and, into the contructor, set it as follow PHP Code: __construct() now you are able to use the database b as usual: PHP Code: $this->db_b->query('YOUR QUERY'); and obviously the default one as follow: PHP Code: $this->db->query('YOUR QUERY'); Make sure to set the persistant connect to false PHP Code: $db['a']['pconnect'] = FALSE; RE: Configure database config from function - vertisan - 02-29-2016 (02-29-2016, 08:36 AM)keulu Wrote: yes you can You don't understand - I know how to use multiple databases. I need to set config this config manualy, because I want to create installer for my APP RE: Configure database config from function - keulu - 02-29-2016 arf okay, my bad, yes you can by overwriting the config file. in php you can write files http://php.net/manual/fr/function.fwrite.php you just have to remove the old database config and rewrite the new one ![]() RE: Configure database config from function - siburny - 02-29-2016 You can pass array of patamteres to database loader like this: PHP Code: $config['hostname'] = 'localhost'; |