WordPress.org

Ready to get started?Download WordPress

Forums

How to change message "Error establishing a database connection" (8 posts)

  1. liquidrice
    Member
    Posted 5 years ago #

    Is there a way to change this message to say something else.

    Would be nice to add that the site will be back in a few mins or something.

    " Error establishing a database connection. This website will be back in a few minutes."

  2. dor
    Member
    Posted 5 years ago #

    Somewhere there is a plugin for maintenance mode, if i can remember.

    May be it isn't what you want exactly, but... i guess you can not change php error messages so easy.

  3. whooami
    Member
    Posted 5 years ago #

    Would be nice to add that the site will be back in a few mins or something.

    create the file, this functionality is already available.

    // Load custom DB error template, if present.
    	if ( file_exists( WP_CONTENT_DIR . '/db-error.php' ) ) {
    		require_once( WP_CONTENT_DIR . '/db-error.php' );
    		die();
    	}

    wp-content/db-error.php <---- assuming you havent changed your content dir.

  4. dor
    Member
    Posted 5 years ago #

    Thank you whooami.

  5. vici
    Member
    Posted 4 years ago #

    where is this functionality code placed? I mean in which php file?
    I'm asking because it doesn't work for me even though I placed a file db-error.php in the wp-content directory

  6. thetooon
    Member
    Posted 4 years ago #

    @vici: wp-includes/functions.php - dead_db()

  7. thetooon
    Member
    Posted 4 years ago #

    It seems that it doesn't work for me neither.

  8. thetooon
    Member
    Posted 4 years ago #

    It will never work.

    Because in wp-includes/wp-db.php on line 372, if connection to db failed - it failed. Without even attempt to call dead_db():

    `
    $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true);
    if (!$this->dbh) {
    $this->bail(sprintf(/*WP_I18N_DB_CONN_ERROR*/"
    <h1>Error establishing a database connection</h1>
    <p>This either means that the username and password information in your wp-config.php file is incorrect or we can't contact the database server at %s. This could mean your host's database server is down.</p>

    • Are you sure you have the correct username and password?
    • Are you sure that you have typed the correct hostname?
    • Are you sure that the database server is running?

    <p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.</p>
    "/*/WP_I18N_DB_CONN_ERROR*/, $dbhost), 'db_connect_fail');
    return;
    }`

    Looks like dead_db() is a orphan function.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags