Environment Based Database Selection In Drupal

I needed to find a way to have only one settings.php file maintain my database configurations across both my local development and environment and my production server. Here is my solution. Is there a better way?

 

if($_SERVER['SERVER_NAME'] == "local.mydomain.com"){
  $db_url = 'mysql://username:password@localhost/databasename';
}
else{
  $db_url = 'mysql://username:password@production/databasename';
}
comments powered by Disqus

© Balanced Scale Media, LLC. All right reserved.