WordPress.org

Support

Support » How-To and Troubleshooting » Error establishing a database connection – frustrated

Error establishing a database connection – frustrated

  • I get this message when I try to access my site.
    The site was working properly, and I tried to add google analytics…
    Anyway, sodabrasil was a site created out of WP.
    sodabrasil.com/paskin was WP.
    We did the integration of logins. Everything was working.
    When I run http://sodabrasil.com/dbtest.php, it says it’s connected.
    this is the debug code.

    <?php
    //connect to MySQL Server
    $conn = mysql_connect("localhost", "*****", "******");
    if (!$conn)
      {
        die(mysql_error());
      }
    else
      {
        echo "1. Successfully connected to MySQL database server.
    
    ";
      }
    // select database
    $db_sel = mysql_select_db('houswe5_securelogin', $conn);
    if (!$db_sel)
      {
        die ('cant\'t use database: ' . mysql_error());
      }
    else
      {
        echo "2. WordPress database selected. ";
      }
    ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    securelogin is the sodabrasil DB for the login.
    But accessing sodabrasil is blocked even before the login!!!

    I am not a professional coder, which makes things a lot harder.

    Thank you for you help.

    G.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Just another piece of information: If you try to access the real config file, it throws the error message, with same credentials. The whole site, sodobrasil.com is down, not only the config file.

    <?php
    error_reporting(E_ALL);
    ini_set("display_errors", 1);
    define('WP_USE_THEMES', false);
    //echo $_SERVER['DOCUMENT_ROOT'];
    //die;
    //require_once('./blog/wp-blog-header.php');
    
    require_once('/home/houswe5/public_html/sodabrasil.com/paskin/wp-blog-header.php');
    global $mysqli;
    $server = 'localhost'; // The host you want to connect to.
    $username = '****'; // The database username.
    $password = '*****'; // The database password.
    $database = '*******'; // The database name.
    $dbms = 'MySQL 5';
    $dbport = '3306';
    //$dbh = mysql_connect($server, $username, $password) or die("Unable to connect to SQL server");
    //$my_db = @mysql_select_db($database) or die("Unable to select database");
    
    $mysqli = new mysqli($server, $username, $password, $database);
    //$mysqli = mysqli_connect($server, $username, $password, $database) or die("Error " . mysqli_error($link));
    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;die;
    }
    // If you are connecting via TCP/IP rather than a UNIX socket remember to add the port number as a parameter.
    ?>

    Thank you so much for any possible suggestion.

    That config file doesn’t look like a standard wordpress config file. I suggest looking for wp-config-sample in your wordpress folder and save it as wp-config.php and try that.

    That config file is for a site that was not WP origanally, but got login integrated to the blog …/blog (in my case …/paskin).
    This blog has standard config file, regular installation. And it’s working! It’s just the root (the original non WP site) that is not working. Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Error establishing a database connection – frustrated’ is closed to new replies.