Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple database option #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions config/config.dev.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,38 @@
* @author Focus Lab, LLC <[email protected]>
*/

//single database usage
$env_db['hostname'] = 'localhost';
$env_db['username'] = '';
$env_db['password'] = '';
$env_db['database'] = '';


$env_config['webmaster_email'] = '[email protected]';

/**
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'] = '[email protected]';


Expand Down
25 changes: 24 additions & 1 deletion config/config.master.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down