Post Pic

How to create a custom database error page

As a WordPress user, you probably had the infamous “Error establishing a database connection” error at least once. This error occurs when your database can’y handle a request. On cheap hosts, this can happen often. Today, I’m showing you how to give a custom style to this error page.

Paste the code below into a new file. Name it db-error.php and save it on your wp-content directory. In case of a database error, WordPress will automatically use this file.

<?php // custom WordPress database error page

  header('HTTP/1.1 503 Service Temporarily Unavailable');
  header('Status: 503 Service Temporarily Unavailable');
  header('Retry-After: 600'); // 1 hour = 3600 seconds

  // If you wish to email yourself upon an error
  // mail("your@email.com", "Database Error", "There is a problem with the database!", "From: Db Error Watching");

?>

<!DOCTYPE HTML>
<html>
<head>
<title>Database Error</title>
<style>
body { padding: 20px; background: red; color: white; font-size: 60px; }
</style>
</head>
<body>
  You got problems.
</body>
</html>

Thanks to CSS Tricks for the tip!

3 Responses

Jun 20 2012 07:40

Is this auto generated on any database error? I do actually use this on a file already but it is a specific file outside of the wp-content folder.

Jun 20 2012 15:42

Ah ha Interesting !

Just the info I needed !

Will definitely share this great tip with all my blogger friends !

May 21 2013 22:36

You got problems.

LOL error message is as helpful as a Chocolate Coffee Mug.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox