Cannot connect to database with credentials provided in db.php I'm trying to push a site live today and am running into a problem I'm having trouble solving. I have a staging site which is a subdomain on the live server and everything works fine there but when I try to load the live site I get the following error (strange characters and all):


  An exception has been thrown during the rendering of a template ("Craft can't connect to the database with the credentials in craft/config/db.php.") in "_includes/_main_nav" at line 19.


The only difference between the two config files is the database name in db.php and the siteUrl and fileSystemPath in general.php. I do have a multi-environment config based on the one at straughtupcraft.com but I don't see any other difference between my live and staging environments other then what is already noted above.

Anyone run across this problem yet? Solutions?

UPDATE:

index.php:

&lt;?php

//die('hey');


// Path to your craft/ folder
$craftPath = '../craft';

// Do not edit below this line
$path = rtrim($craftPath, '/').'/app/index.php';

if (!is_file($path))
{
    exit('Could not find your craft/ folder. Please ensure that &lt;strong&gt;&lt;code&gt;$craftPath&lt;/code&gt;&lt;/strong&gt; is set correctly in '.__FILE__);
}

require_once $path;


// Check the SERVER_NAME variable ourselves
switch ($_SERVER['SERVER_NAME']) 
{
    // If the SERVER_NAME variable matches our case, 
    // assign the CRAFT_ENVIRONMENT variable a keyword 
    // that identifies this environment that we can 
    // use in our multi-environment config

    case 'site.com' :
        define('CRAFT_ENVIRONMENT', 'live');
        break;

    case 'staging.site.com' :
        define('CRAFT_ENVIRONMENT', 'staging');
        break;

    default :
        define('CRAFT_ENVIRONMENT', 'dev');
        break;
}


general.php
    

return array(
    '*' =&gt; array(
        'cpTrigger' =&gt; 'site_admin',
        'omitScriptNameInUrls' =&gt; true,
        'slugWordSeparator' =&gt; "_",
    ),
    'live' =&gt; array(
        'environmentVariables' =&gt; array(
            'siteUrl' =&gt; 'http://site.com',
            'fileSystemPath' =&gt; '/path/to/domains/site.com/html'
        )
    ),
    'staging' =&gt; array(
        'devMode' =&gt; true,
        'environmentVariables' =&gt; array(
            'siteUrl' =&gt; 'http://staging.site.com',
            'fileSystemPath' =&gt; '/path/to/domains/staging.site.com/html'
        )
    ),
    'dev' =&gt; array(
        'devMode' =&gt; true,
        'environmentVariables' =&gt; array(
            'siteUrl' =&gt; 'http://site.dev',
            'fileSystemPath' =&gt; '/users/stubear/sites/site/dev/html'
        )
    ),
);


db.php
    

return array(
    '*' =&gt; array(
        'tablePrefix' =&gt; 'craft',
    ),
    'live' =&gt; array(
        'server' =&gt; 'server',
        'user' =&gt; 'username',
        'password' =&gt; '********',
        'database' =&gt; 'craft_live_db',
    ),
    'staging' =&gt; array(
        'server' =&gt; 'server',
        'user' =&gt; 'username',
        'password' =&gt; '********',
        'database' =&gt; 'craft_staging_db',
    ),
    'dev' =&gt; array(
        'server' =&gt; 'localhost',
        'user' =&gt; 'root',
        'password' =&gt; 'root',
        'database' =&gt; 'site-dev',
    ),
);
Move the check the SERVER_NAME switch up above the require_once $path;. You need to set CRAFT_ENVIRONMENT earlier.