Create a new php file called environments.php save it into the anchor folder and add this content:
<?php
// Define Environments - may be a string or array of options for an environment
$environments = array(
'local' => array('.local', 'local.'),
'development' => '.dev',
'staging' => 'stage.',
'preview' => 'preview.',
);
// Get Server name
$server_name = $_SERVER['SERVER_NAME'];
foreach($environments AS $key => $env)
{
if(is_array($env))
{
foreach ($env as $option)
{
if(stristr($server_name, $option))
{
define('WEB_ENV', $key);
break 2;
}
}
}
else
{
if(strstr($server_name, $env))
{
define('WEB_ENV', $key);
break;
}
}
}
// If no environment is default to production
if(!defined('WEB_ENV')) define('WEB_ENV', 'production');
Open the root index.php and just above where it says require SYS . 'start' . EXT;
around line 33 add require APP .'environments' .EXT;
:
<?php
/*
/ \
| o |
\ /
________) (________
| |
'------. .------'
| |
| |
| |
| |
/\ | | /\
/_ \ / \ / _\
\ '. .' '. .' /
\ '--' '--' /
'. .'
'._ _.'
`'-. .-'`
\ /
*/
define('DS', DIRECTORY_SEPARATOR);
define('ENV', getenv('APP_ENV'));
define('VERSION', '0.9.1');
define('PATH', dirname(__FILE__) . DS);
define('APP', PATH . 'anchor' . DS);
define('SYS', PATH . 'system' . DS);
define('EXT', '.php');
require APP .'environments' .EXT;
require SYS . 'start' . EXT;
Open anchor/config/db.php
and in place of the database connection info paste the following:
<?php
switch (WEB_ENV)
{
case 'local':
case 'development':
case 'staging':
case 'preview':
return array(
'default' => 'mysql',
'prefix' => 'anchor_',
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'hostname' => 'localhost',
'port' => '',
'username' => 'root',
'password' => 'root',
'database' => 'anchor',
'charset' => 'utf8'
)
)
);
break;
case 'production':
return array(
'default' => 'mysql',
'prefix' => 'anchor_',
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'hostname' => 'HOST',
'port' => '',
'username' => 'USER',
'password' => 'PASS',
'database' => 'DATABASE',
'charset' => 'utf8'
)
)
);
break;
default:
break;
}
Remember to save your current database connection and paste it into he correct place in the switch. You can now add the info for multiple database connections depending on the environment.