Skip to main content
Yoosuf Mohamed

Engineering

A Better Way to Show WordPress Database Errors

A cleaner approach to displaying WordPress database errors for easier debugging during development.

1 min read

By Yoosuf Mohamed, Systems Architect

If you visit this website often, you may have noticed some downtime (due to issues with the Amazon Cloud servers). I got tired of seeing that ugly default error message, so I decided to override the WordPress database error message with something friendlier for users. To do this, I followed a blog post by Jeff Starr, and it worked like a charm.

Better way to display WordPress Database Error

Create a file named db-error.php in the wp-content directory and paste in the following code. Feel free to style it however you like.

         <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Terribly sorry :(</title>
</head>
<body>
<div class="container">
<h1>Terribly sorry <span>:(</span></h1>
<p>I am sorry, looks like the Amazon Cloud Servers aren't responding or are having some technical issues right now.</p>
<p>Sometimes refreshing the browser may work, hit on the refresh button or press CMD + R / CTRL + F5</p>

</div>
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'YOUR GOOGLE ANALYTICS ID']);
_gaq.push(['_setDomainName', 'YOUR DOMAIN']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
_gaq.push(['_setCustomVar', 1, '500 Error', 'Error site Loading', 1]);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</script>

</body>
</html>              

Feel free to share it anywhere you like.

  • WordPress
  • Debugging
  • PHP
  • Database Errors

Let's build something that scales.

Planning an AI product, automating a workflow, or taking a platform to production? I'd love to hear what you're building.