12-28-2012, 04:55 AM
[eluser]ladooboy[/eluser]
Hi !
I've got two sets of databases.
Users
Data1
I have to make 1 call at login time to Users db to get the correct DB connection details out of the db and then load the new database to be used for the rest of the session.
Basically this is what I do:
In MY_MODEL I do this:
I want to make sure it saves the connection of the dynamic db connection in the superglobal, so I can re use it in every model(not sure if that's the right way ?)
My problem is that this works for the current model, but as soon as I try to make the call from a different model the superglobal udb is empty and it can't find the reference to my dynamic DB anymore.
Here are my config settigs
This is my config array from the DB:
How can I make sure the new DB connection is available throughout my application without having to re-establish a new connection every time (pconnect is set to TRUE for the dynamic one).
Any help is appreciated.
Hi !
I've got two sets of databases.
Users
Data1
I have to make 1 call at login time to Users db to get the correct DB connection details out of the db and then load the new database to be used for the rest of the session.
Basically this is what I do:
Code:
$CI->udb = $this->load->database($database_details,TRUE);
$this->udb = & $CI->udb;
In MY_MODEL I do this:
Code:
$CI =& get_instance();
$this->udb = $CI->udb;
I want to make sure it saves the connection of the dynamic db connection in the superglobal, so I can re use it in every model(not sure if that's the right way ?)
My problem is that this works for the current model, but as soon as I try to make the call from a different model the superglobal udb is empty and it can't find the reference to my dynamic DB anymore.
Here are my config settigs
Code:
$db['localhost']['hostname'] = 'localhost';
$db['localhost']['username'] = 'root';
$db['localhost']['password'] = '';
$db['localhost']['database'] = 'user';
$db['localhost']['dbdriver'] = 'mysql';
$db['localhost']['dbprefix'] = '';
$db['localhost']['pconnect'] = FALSE;
$db['localhost']['db_debug'] = TRUE;
$db['localhost']['cache_on'] = FALSE;
$db['localhost']['cachedir'] = '';
$db['localhost']['char_set'] = 'utf8';
$db['localhost']['dbcollat'] = 'utf8_general_ci';
$db['localhost']['swap_pre'] = '';
$db['localhost']['autoinit'] = FALSE;
$db['localhost']['stricton'] = FALSE;
This is my config array from the DB:
Code:
$db['localhost']['hostname'] = 'localhost';
$db['localhost']['username'] = 'root';
$db['localhost']['password'] = '';
$db['localhost']['database'] = 'data1';
$db['localhost']['dbdriver'] = 'mysql';
$db['localhost']['dbprefix'] = '';
$db['localhost']['pconnect'] = TRUE;
$db['localhost']['db_debug'] = TRUE;
$db['localhost']['cache_on'] = FALSE;
$db['localhost']['cachedir'] = '';
$db['localhost']['char_set'] = 'utf8';
$db['localhost']['dbcollat'] = 'utf8_general_ci';
$db['localhost']['swap_pre'] = '';
$db['localhost']['autoinit'] = FALSE;
$db['localhost']['stricton'] = FALSE;
How can I make sure the new DB connection is available throughout my application without having to re-establish a new connection every time (pconnect is set to TRUE for the dynamic one).
Any help is appreciated.