How to Customize, Modify or Change WordPress Database Connection Error Page

When WordPress, a popular blog publishing platform built in PHP and uses MySQL database, cannot connect or having problem connecting to the database (such as when database is down), or the MySQL server has too many connections exceeding maximum connection allowed (especially when your post or article is been dugg on Digg.com) and rejects or denies new incoming connections, WordPress will display a default “error establishing database connection” error message page. However, the WordPress error page, some is shown below, is not visitor friendly or user friendly, and worse, the default database error page also reveals the SQL server address and name.

Can’t select database

We were able to connect to the database server (which means your username and password is okay) but not able to select the localhost database.

* Are you sure it exists?
* On some systems the name of your database is prefixed with your username, so it would be like username_wordpress. Could that be the problem?

If you don’t know how to setup a database you should contact your host. If all else fails you may find help at the WordPress Support Forums.

Error establishing a database connection

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 localhost. This could mean your host’s database server is down.

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?

These default Wordpress database error pages are more meant for website administrators or webmasters rather than the public visitors. However, you can change the error page to another different error page by modifying or altering wordings and text in the error page by customizing the wp-db.php file located in wp-include directory. Here’s how you can hack the Wordpress default error message.

In wp-db.php (the file that handles the database connections that WordPress makes), you can see lines like “DB Constructor – connects to the server and selects a database” and “Select a DB (if another one needs to be selected)”. That’s where you can alter the text and word in the error page. Just look carefully after the line, you will see exactly the some text and message as appeared on the database error page. Edit them to your liking.

Wordpress Bail Function
Beside, from line 312 onwards is the header and footer output for the HTML of database connection error page, contains inside function named “bail”, which specifies things like the title of “WordPress: Error”. The “bail” function is called whenever a database connection error is encountered, and does what it’s name said – bails out the error and displays an error message instead to notify the users. You can change them if you like too.

Please take a backup of wp-db.php file before you customize or alter it. If you break the code, your website visitors and surfers will get the PHP error instead. Beside, be careful that when you upgrade your WordPress. If you overwrite all files when upgrade the WordPress, the wp-db.php will be replaced back with the original unchanged version too, and you have to edit the file again. Else, backup the wp-db.php before upgrading your WordPress and restore it after upgrading is done.

One Response to “How to Customize, Modify or Change WordPress Database Connection Error Page”

  1. Zane
    March 21st, 2009 23:51
    1

    Thanks!
    You Saved Me Here!

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe to comments feature has been disabled. To receive notification of latest comments posted, subscribe to My Digital Life Comments RSS feed or register to receive new comments in daily email digest.

New Articles

Incoming Search Terms for the Article

wordpress database connection - wordpress change database - change wordpress database - wordpress change database password - wordpress change database connection - change wordpress database connection - change wordpress database password - change database wordpress - wordpress Error establishing a database connection - database connection wordpress - wordpress error establishing database connection - wordpress edit database - wordpress db connection - wordpress database connection file - "Error establishing a database connection" change default page - changing wordpress database - how to change database for wordpress blog - wordpress connect to database - wordpress change db config - wordpress zmena database - change database password in wordpress - change database connection wordpress - edit wordpress database connection - how to change wordpress db information - how to change wordpress database - wordpress config change db login - wordpress change database info - wordpress change sql - change database info wordpress - which file handles database connection in wordpress - wordpress where is db connection - wordpress change db connection - wordpress database SQL server - wordpress how do I change the database - Connection Error to NDO DataBase ! - connect wordpress db - customising wordpress "Error establishing a database connection" - how to connect to a wordpress database - how to change the database connection in wordpress - wordpress number of db connections - change database in wordpress - changing the database of wordpress - connect to db wordpress - how to change database pass in wordpress - how to manage and edit database in wordpress - netpivotal wordpress database connection details - php wordpress how to include database connection file - wordpress how to connect to database - wordpress plugin database conection - wordpress set database -