In your case, I believe you have to create an extra configuration while running the program. From according to the documentation you can change the DB configuration as follows:
<?php
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";
$this->load->database($config);
Or use two settings at the same time:
$dbBase = $this->load->database('default', TRUE);
$dbUser = $this->load->database($config, TRUE);
// Dispara query para o banco principal
$dbBase->query();
// Dispara query para o banco do usuario
$dbUser->query();
Just change the array $config
of the parameters you have in the session (outside the database.php
file).
$config['hostname'] = $this->session->userdata('host');
$config['username'] = $this->session->userdata('user');
$config['password'] = $this->session->userdata('password');
$config['database'] = $this->session->userdata('database');
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";