Staging Server Database Not Connecting I've moved my site to the staging server but now I'm getting a craft can't connect to the database with credentials in craft/config/db.php

Thing is I uploaded this script with the same credentials and it connects just fine. Any idea what I could be doing wrong

&lt;?php
# Fill our vars and run on cli
# $ php -f db-connect-test.php
$dbname = 'name';
$dbuser = 'user';
$dbpass = 'pass';
$dbhost = 'localhost';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
​
echo "connected to the database";


My full db.php file with actual db creds removed - updated to include domain from live site.

&lt;?php
​
/**
 * Database Configuration
 *
 * All of your system's database configuration settings go in here.
 * You can see a list of the default settings in craft/app/etc/config/defaults/db.php
 */
​
return array(
    '*' =&gt; array(
        'tablePrefix' =&gt; 'craft',
    ),
    'nec.dev' =&gt; array(
        'server' =&gt; 'localhost',
        'user' =&gt; 'root',
        'password' =&gt; 'root',
        'database' =&gt; 'nec',
    ),
    'nec.dev.stagingdomain.com' =&gt; array(
        'server' =&gt; 'localhost',
        'user' =&gt; 'staging-user',
        'password' =&gt; 'staging-password',
        'database' =&gt; 'staging-database',
    ),
    'nec-inc.com' =&gt; array(
        'server' =&gt; 'localhost',
        'user' =&gt; '',
        'password' =&gt; '',
        'database' =&gt; '',
    ),
);


I can't figure out why this doesn't work on staging when the same credentials work with the connection testing script.
It looks as if you've sorted thing out (dev.nec... vs nec.dev...)

In general, I find the domain name matching in the config files to be confusing and error prone. I always follow the advice in the Foolproof Multi-Environment Config recipe. Put this at the top of your index.php:

switch (strtolower($_SERVER['SERVER_NAME'])) {
  case 'nec.dev':
    define('CRAFT_ENVIRONMENT', 'DEV');
    break;
  case 'nec.dev.stagingdomain.com':
    define('CRAFT_ENVIRONMENT', 'STAGE');
    break;
  case 'nec-inc.com':
    define('CRAFT_ENVIRONMENT', 'LIVE');
    break;
  default:
    exit('No environment defined for '.$_SERVER['SERVER_NAME']);
}


Then your db.php and general.php will look like this:

return array(
  '*' =&gt; array(...),
  'DEV' =&gt; array(...),
  'STAGE' =&gt; array(...),
  'LIVE' =&gt; array(...),
);


And when you hit dev.nec.stagingdomain.com you will see that No environment defined error and fairly quickly see what is wrong.

(There is also an Enhanced Foolproof Multi-Environment Config recipe)