1

I'm moving a craft install from a development to production server and am getting this error:

ERROR ERROR
Craft can’t connect to the database with the credentials in craft/config/db.php.

I've triple checked the db credentials and permissions and everything is correct. Here's my db.php file:

<?php

// uncommenting this gives me a 'connected okay' so I know that the credentials are correct.
// if ($con=mysqli_connect("localhost","thandtho_db","*********","thandtho_production")) // {
//  die('connected okay');
// } else {
//  die('couldn\'t connect');
// } 

/**
 * 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
 */

// Import your local config settings
require( 'config.local.php' );

return array(
    '*'=> array(
        // Database Info
        'tablePrefix' => 'craft',
    // Production Domain
    '9thandthomas.com' => array(
        'server' => 'localhost',
        'user' => 'thandtho_db',
        'password' => '***********',
        'database' => 'thandtho_production'
    ),
    ),
    // Dev
    '9thandthomas.transomco.com' => array(
        'server' => 'localhost',
        'user' => 'ninththomas_dev',
        'password' => '4iJoi58@',
        'database' => 'ninththomas_dev'
    ),
    // Local
    // Needs to be placed after production since subdomain
    // is similar to production domain name.
    $localConfig['envUrl'] =>  array (
        'server' => $localDatabase['server'],
        'user' => $localDatabase['user'],
        'password' => $localDatabase['password'],
        'database' => $localDatabase['database'],
    )
);

************************** ANSWER **************************

I moved the database details from beneath the * and it worked.

db.php now looks like this:

<?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
 */

// Import your local config settings
require( 'config.local.php' );

return array(
    '*'=> array(
        // Database Info
        'tablePrefix' => 'craft',
    ),
    // Production Domain
    '9thandthomas.com' => array(
        'server' => 'localhost',
        'user' => 'thandtho_db',
        'password' => 'wR39fy2!k',
        'database' => 'thandtho_production'
    ),
    // Dev
    '9thandthomas.transomco.com' => array(
        'server' => 'localhost',
        'user' => 'ninththomas_dev',
        'password' => '4iJoi58@',
        'database' => 'ninththomas_dev'
    ),
    // Local
    // Needs to be placed after production since subdomain
    // is similar to production domain name.
    $localConfig['envUrl'] =>  array (
        'server' => $localDatabase['server'],
        'user' => $localDatabase['user'],
        'password' => $localDatabase['password'],
        'database' => $localDatabase['database'],
    )
);
3

I had a similar issue where my '*' was being chosen all of the time, meaning all my environments used the same DB details.

Possibly try splitting it up, and not have a '*' for your DB details, for any environment?

| improve this answer | |
  • No problem! Threw me off first time as well :) Glad it helped. – Jason Mayo Jun 24 '15 at 18:46
3

Assuming that really was your db.php, you have '9thandthomas.com' inside the * array, not beneath it:

return array(
  '*' => array(
    ...
    '9thandthomas.com' => array( ... )
  ),
  // '9thandthomas.com' SHOULD BE HERE
  ...
)
| improve this answer | |
  • Yeah Marion, that was the problem. Not sure how it got where it was... – Andrew Means Jun 25 '15 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.