• Resolved cortes

    (@cortes)


    I closed my last question because I thought my problem wasn’t WordPress related. After chasing some ghosts, I’m back to WordPress as the culprit. I’m getting the infamous “Error establishing a database connection” message when I invoke index.php on a brand new WordPress install. This is relevant information from my wp-config:

    define(‘DB_NAME’, ‘gazos’);
    define(‘DB_USER’, ‘root’);
    define(‘DB_PASSWORD’, ‘somepassword’);
    define(‘DB_HOST’, ‘localhost:3306’);

    I also tried localhost without the port and got the same error.

    To isolate the problem, I ran the following code from the same directory as WordPress via the browser:

    <?php
    $mysqli = new mysqli('localhost:3306', 'root', 'somepassword', 'gazos');
    
    if ($mysqli->connect_error)
        die('Connect Error (' . $mysqli->connect_errno . ') '. $mysqli->connect_error);
    else
        echo 'Good connection to gazos';
    ?>

    I get a good connection. It fails if I remove the port. I’m running PHP 5.4.13 and MySQL 5.0.10. Could it be that my PHP version is too new?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Is this a local install?

    Thread Starter cortes

    (@cortes)

    It’s on my development machine: a Mac Mini running OS X Mountain Lion.

    [Moved to Localhost Installs]

    I think you need to ask about this on a forum dedicated to your server software. It’s a server configuration issue.

    Thread Starter cortes

    (@cortes)

    I’m confused. The code i cited above works just fine with the server so the server is configured correctly to run that code. Are you saying I have to specially configure the server to work with WordPress? I have another non-Wordpress local website that also works just fine with the server.

    A correctly configured server would not need to provide a port as part of the host name when connecting to any database.

    Thread Starter cortes

    (@cortes)

    The answer to the problem was to use 127.0.0.1 without a port in place of localhost.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘WordPress Won't Connect to DB, But Test Code Does’ is closed to new replies.