You will need to have a main database for the user authentication and storing the information anyway right? So you need to manage two connections. You can have your default connection in there, then set your 2nd config in MY_Controller.
This MY_Controller would handle the user detection (from the auto-loaded database class and whatever model/lib/auth system you are using) then it would of course get the database name from the user however it may be attached.
You can then use code like this to set a 2nd db:
class MY_Controller extends Controller
{
function MY_Controller () {
parent::Controller();
$this->user = $this->auth->get_user($this->input->post('username'), $this->input->post('password'));
$this->company = $this->company->get($this->input->post('company_id'));
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = $this->company->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";
$this->company_db = $this->load->database($config, TRUE);
}
}
You can then interact with $this->company_db as well as $this->db. The former would be for db interactions with their database, the latter being for interactions with the main default connection.