Welcome Guest, Not a member yet? Register   Sign In
Store multiple DB connection strings in database...
#1

[eluser]Unknown[/eluser]
is there a solution to store multiple DB connection strings for several databases (Oracle, MSSQL, PostGres, etc) in a database table? like a virtual configuration string that connects to a specific database based on a call.

I have several databases I'll need to connect to but don't want to add each DB configuration in the database.php config file.

e.g:
Default MySQL config will keep all the connection strings

Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'user';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;


Now, If the data requested requires MSSQL driver, pull config from default MySQL database.

Code:
$db['mssql']['hostname'] = '$host';
$db['mssql']['username'] = '$username';
$db['mssql']['password'] = '$password';
$db['mssql']['database'] = '$database';
$db['mssql']['dbdriver'] = 'mssql';

Now, If the data requested requires Oracle driver, pull config from default MySQL database.

Code:
$tnsname = '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = x.x.x.x)(PORT = xxxx))
(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = my_service_name)))';
$db['oci8']['hostname'] = $tnsname;
$db['oci8']['username'] = '$username';
$db['oci8']['password'] = '$password';
$db['oci8']['database'] = '$database';
$db['oci8']['dbdriver'] = 'oci8';
And so on...


Messages In This Thread
Store multiple DB connection strings in database... - by El Forum - 07-08-2014, 01:40 PM
Store multiple DB connection strings in database... - by El Forum - 07-08-2014, 02:15 PM
Store multiple DB connection strings in database... - by El Forum - 07-08-2014, 02:24 PM
Store multiple DB connection strings in database... - by El Forum - 07-08-2014, 02:48 PM



Theme © iAndrew 2016 - Forum software by © MyBB