I am currently building an app whereby a user will be able to enter their own personal DB connections to utilise data from their MySQL database.
This means I will have two DB connections - my local (managing sessions etc) and the users remote one.
Can anyone advise on the best way to manage these two connections? I have looked at db groups - http://codeigniter.com/user_guide/database/connecting.html however the users db connection will be set by session vars, so I cannot put the details of the remote db in the config file.
I have tried manually setting a new db group within my class like:
$db['foreign']['hostname'] = $this->session->userdata('hostname');
$db['foreign']['username'] = $this->session->userdata('dbuser');
$db['foreign']['password'] = $this->session->userdata('dbpassword');
$db['foreign']['database'] = $this->session->userdata('dbname');
$db['foreign']['dbdriver'] = "mysql";
$db['foreign']['dbprefix'] = "";
$db['foreign']['pconnect'] = FALSE;
$db['foreign']['db_debug'] = TRUE;
$db['foreign']['cache_on'] = FALSE;
$db['foreign']['cachedir'] = "";
$db['foreign']['char_set'] = "utf8";
$db['foreign']['dbcollat'] = "utf8_general_ci";
$foreign_db = $this->load->database('foreign', TRUE);
But i get an exception on the load line:
You have specified an invalid database connection group.
Can anyone advise how I can achieve this?
Many thanks, Ben.