Welcome Guest, Not a member yet? Register   Sign In
Configure database config from function
#3

(02-29-2016, 08:36 AM)keulu Wrote: 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';
$db['a']['username'] = 'user';
$db['a']['password'] = 'pw';
$db['a']['database'] = 'db1';
...

$db['b']['hostname'] = 'localhost';
$db['b']['username'] = 'user';
$db['b']['password'] = 'pw';
$db['b']['database'] = 'db2';
...

//set the default db
$active_group 'a'

then on your model initialize a class variable:
PHP Code:
private $db_b

and, into the contructor, set it as follow
PHP Code:
__construct()
{
   ...
   
$this->db_b $this->load->database('b'TRUE); 


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;
$db['b']['pconnect'] = FALSE

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
Reply


Messages In This Thread
RE: Configure database config from function - by vertisan - 02-29-2016, 08:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB