From 30971a5d36131791515e6072d130887e1c6a74e1 Mon Sep 17 00:00:00 2001 From: Eric Lamb Date: Sun, 15 Jul 2012 12:07:04 -0600 Subject: [PATCH] Added mechanism to use multiple databases Example usage is in config.dev.php Instructions: you use a multidimensional array for database credentials. Master uses "expressionengine" for the key and all others follow Backwards compatibility with single databases is maintained. Note: You MUST include all database config keys for additional databases (included in config.dev.php) --- config/config.dev.php | 26 ++++++++++++++++++++++++++ config/config.master.php | 25 ++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/config/config.dev.php b/config/config.dev.php index 562ff9d..992cad1 100644 --- a/config/config.dev.php +++ b/config/config.dev.php @@ -10,12 +10,38 @@ * @author Focus Lab, LLC */ +//single database usage $env_db['hostname'] = 'localhost'; $env_db['username'] = ''; $env_db['password'] = ''; $env_db['database'] = ''; +$env_config['webmaster_email'] = 'dev@domain.com'; + +/** +Example of multiple database usage +$env_db['expressionengine']['hostname'] = ''; +$env_db['expressionengine']['username'] = ''; +$env_db['expressionengine']['password'] = ''; +$env_db['expressionengine']['database'] = ''; + +$env_db['another_db']['hostname'] = ''; +$env_db['another_db']['username'] = ''; +$env_db['another_db']['password'] = ''; +$env_db['another_db']['database'] = ''; +$env_db['another_db']['dbprefix'] = ''; +$env_db['another_db']['swap_pre'] = ''; +$env_db['another_db']['dbdriver'] = 'mysql'; +$env_db['another_db']['pconnect'] = FALSE; +$env_db['another_db']['db_debug'] = TRUE; +$env_db['another_db']['cache_on'] = FALSE; +$env_db['another_db']['autoinit'] = FALSE; +$env_db['another_db']['char_set'] = 'utf8'; +$env_db['another_db']['dbcollat'] = 'utf8_general_ci'; +$env_db['another_db']['cachedir'] = ''; +*/ + $env_config['webmaster_email'] = 'dev@domain.com'; diff --git a/config/config.master.php b/config/config.master.php index 8d7bf8e..d9ebca4 100644 --- a/config/config.master.php +++ b/config/config.master.php @@ -64,7 +64,30 @@ $env_db['cachedir'] = APPPATH . 'cache/db_cache/'; // Merge our database setting arrays - $db['expressionengine'] = array_merge($db['expressionengine'], $env_db); + if(isset($env_db['expressionengine'])) //looks like we're dealing with multiple dbs + { + foreach($env_db AS $key => $value) + { + if(!isset($db[$key])) + { + $db[$key] = array(); + } + + if(is_array($env_db[$key])) + { + $db[$key] = array_merge($db[$key], $env_db[$key]); + } + else + { + $db[$key] = $env_db[$key]; + } + } + } + else + { + //default single DB + $db['expressionengine'] = array_merge($db['expressionengine'], $env_db); + } // No need to have this variable accessible for the rest of the app unset($env_db);