CodeIgniter Forums

Full Version: application/config/database.php aware of its location
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Hi guys,
(and girls !)

newbie to CI here,
this is what i did to my /system/application/config/database.php file, in order to stop worrying about it when I sync or re-upload all my files to the production server after massive edits under the localhost environment...

is there a better way to achieve this ?
many thanks !

Code:
if (($_SERVER['SERVER_NAME']=='www.production_site.com') || ($_SERVER['SERVER_NAME']=='production_site.com')) {
    $active_group = "production_site";
} elseif ($_SERVER['SERVER_NAME']=='localhost') {
    $active_group = "localhost_development";
}

$active_record = TRUE;

$db['production_site']['hostname'] = "production_server";
$db['production_site']['username'] = "production_username";
$db['production_site']['password'] = "production_password";
$db['production_site']['database'] = "production_database";
$db['production_site']['dbdriver'] = "mysql";
$db['production_site']['dbprefix'] = "";
$db['production_site']['pconnect'] = TRUE;
$db['production_site']['db_debug'] = TRUE;
$db['production_site']['cache_on'] = FALSE;
$db['production_site']['cachedir'] = "";
$db['production_site']['char_set'] = "utf8";
$db['production_site']['dbcollat'] = "utf8_general_ci";

$db['localhost_development']['hostname'] = "localhost";
$db['localhost_development']['username'] = "development_username";
$db['localhost_development']['password'] = "development_password";
$db['localhost_development']['database'] = "development_database";
$db['localhost_development']['dbdriver'] = "mysql";
$db['localhost_development']['dbprefix'] = "";
$db['localhost_development']['pconnect'] = TRUE;
$db['localhost_development']['db_debug'] = TRUE;
$db['localhost_development']['cache_on'] = FALSE;
$db['localhost_development']['cachedir'] = "";
$db['localhost_development']['char_set'] = "utf8";
$db['localhost_development']['dbcollat'] = "utf8_general_ci";

/* End of file database.php */
/* Location: ./system/application/config/database.php */

El Forum

[eluser]mr.zeno[/eluser]
I just try to not overwrite my server database-config.. works for me Smile

This seems like a nice alternative tough! Smile