I have a codeigniter setup to connect to 2 databases (default and website). I need to change the default database name dynamically, and everything that uses the default connection should also use the new database. Is there any way to do this?
The reason for this is because I want to set up a cron script that runs commands in specific databases. I need to be able to dynamically change this and edit the /config/database.php application is not possible.
$active_group = 'default';
$active_record = TRUE;
$phppos_client_name = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.'));
$db['site']['hostname'] = 'php-pos-db';
$db['site']['username'] = 'phppoint';
$db['site']['password'] = 'password';
$db['site']['database'] = 'phppoint_site';
$db['site']['dbdriver'] = 'mysql';
$db['site']['dbprefix'] = '';
$db['site']['pconnect'] = FALSE;
$db['site']['db_debug'] = FALSE;
$db['site']['cache_on'] = FALSE;
$db['site']['cachedir'] = '';
$db['site']['char_set'] = 'utf8';
$db['site']['dbcollat'] = 'utf8_general_ci';
$db['site']['swap_pre'] = '';
$db['site']['autoinit'] = TRUE;
$db['site']['stricton'] = FALSE;
$db['default']['hostname'] = "php-pos-db";
$db['default']['username'] = "phppoint";
$db['default']['password'] = "password";
$db['default']['database'] = "phppoint_$phppos_client_name";
$db['default']['dbdriver'] = "mysql";
$db['default']['dbprefix'] = "phppos_";
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = FALSE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_unicode_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
/* End of file database.php */
/* Location: ./application/config/database.php */
source
share