Skip to content

Instantly share code, notes, and snippets.

@furzeface
Last active January 2, 2016 03:49
Show Gist options
  • Save furzeface/8246739 to your computer and use it in GitHub Desktop.
Save furzeface/8246739 to your computer and use it in GitHub Desktop.
To allow you to use one db.php file for all local dev/staging/production environments with Anchor CMS.
//Goes in your anchor/config/db.php file
//$$REPLACE_THESE$$ with your demo and live db details
switch ($_SERVER['SERVER_NAME']) {
case 'demo.domain.com': //eg. 'demodaniel.furzeface.com' for me
return array(
'default' => 'mysql',
'prefix' => 'anchor_', //change if you want
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'hostname' => '$$HOSTNAME_GOES_HERE$$',
'port' => 3306,
'username' => '$$USERNAME$$',
'password' => '$$PASSWORD$$',
'database' => '$$DATABASE_NAME$$',
'charset' => 'utf8'
)
)
);
break;
case 'domain.com': //eg 'daniel.furzeface.com' for me
return array(
'default' => 'mysql',
'prefix' => 'anchor_', //change if you want
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'hostname' => '$$HOSTNAME_GOES_HERE$$',
'port' => 3306,
'username' => '$$USERNAME$$',
'password' => '$$PASSWORD$$',
'database' => '$$DATABASE_NAME$$',
'charset' => 'utf8'
)
)
);
break;
default:
return array(
'default' => 'mysql',
'prefix' => 'anchor_', //change if you want
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'hostname' => 'localhost', //or domain.dev or whatever you use
'port' => 8889,
'username' => 'root',
'password' => 'root',
'database' => '$$DATABASE_NAME$$',
'charset' => 'utf8'
)
)
);
break;
}
//You get the idea!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment