"Error establishing database connection" but script says "connection successful" (7 posts)

  1. plauren
    Posted 3 years ago #

    I have imported my site(Wp 3.2.1) to a new Hosting and it is showing “Error establishing a database connection”. The name of the server, user and password are correct. In fact, I am running this script and the answer is "connection succeeded"

    $db = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    if (!$db) echo "connection failed";
    else echo "connection succeeded";

    I cannot access wp-admin either so I have disabled the plugins and set the default theme using phpmyadmin, but no luck. I have also changed the permission flags in the files but still I am getting “Error establishing a database connection”. I have run the database repair script but still not working.

    I have uploaded the site to a free Hosting( freehostia, mysql version 5.0.51a, PHP version 5.2.17) and it works perfectly there. But I would like to run it in my hosting (cpanel,mysql version 5.1.68 and PHP version 5.3.23)

    I have already contacted my Hosting provider but the were not much help, just suggested me to check the connection parameters.

    Has anyone a clue of what is going wrong or what should I do?

  2. Archie22is
    Posted 3 years ago #


    It shouldn't be that difficult really, edit your WordPress (wp-config.php) with the correct settings (for you live server)

    /** The name of the database for WordPress */
    define('DB_NAME', 'your_database');
    /** MySQL database username */
    define('DB_USER', 'root');
    /** MySQL database password */
    define('DB_PASSWORD', 'password');
    /** MySQL hostname */
    define('DB_HOST', 'yourlivehost');

    Edit you database (siteurl) & (home) - this could just be your problem.

  3. Krishna
    Posted 3 years ago #

    Can you post your site URL?

  4. plauren
    Posted 3 years ago #

  5. Krishna
    Posted 3 years ago #

  6. railpnrstatus
    Posted 3 years ago #

    I had found the solutions on the web...this can be happen because of so many reasons..you can check out the solutions below...



  7. Krishna
    Posted 3 years ago #

    Is this explained in the links above?

Topic Closed

This topic has been closed to new replies.

About this Topic