Skip to content

Instantly share code, notes, and snippets.

@mrw
Created November 1, 2010 16:00
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrw/658413 to your computer and use it in GitHub Desktop.
Save mrw/658413 to your computer and use it in GitHub Desktop.
Inside config/database.php: Use a switch statement and the active group in EE2 to set database information based on which server you're currently accessing.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// Multiple if statements, or a switch statement,
// can handle as many environments as you need
if ($_SERVER['HTTP_HOST'] == "local-site.dev") {
$active_group = 'expressionengine';
} else {
$active_group = 'enginehosting';
}
$active_record = TRUE;
$db['expressionengine']['hostname'] = "localhost";
$db['expressionengine']['username'] = "local username";
$db['expressionengine']['password'] = "local password";
$db['expressionengine']['database'] = "local database";
$db['expressionengine']['dbdriver'] = "mysql";
$db['expressionengine']['dbprefix'] = "exp_";
$db['expressionengine']['pconnect'] = FALSE;
$db['expressionengine']['swap_pre'] = "exp_";
$db['expressionengine']['db_debug'] = TRUE;
$db['expressionengine']['cache_on'] = FALSE;
$db['expressionengine']['autoinit'] = FALSE;
$db['expressionengine']['char_set'] = "utf8";
$db['expressionengine']['dbcollat'] = "utf8_general_ci";
$db['expressionengine']['cachedir'] = "";
// Copies most of the settings from the above connection
$db['enginehosting'] = $db['expressionengine'];
$db['enginehosting']['hostname'] = "production server hostname";
$db['enginehosting']['username'] = "production server username";
$db['enginehosting']['database'] = "production server database";
/* End of file database.php */
/* Location: ./system/expressionengine/config/database.php */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment