Database connection has a big role when we build using a dynamic webpage. To be more spesific, if we’re using WordPress it’s always a good thing to have our database connection alive. But, for some technical situation, database connection might be dropped. Like or not, this is the situation we might have.
To deal with high-traffic website, there is a WordPress plugin (note: we’re talking about WordPress here) called WP Super Cache. This plugin will help your WordPress installation to deal with major traffic, to keep our site alive e.g. when our site got a massive traffic from site like Digg or Slashdot. When there is a failure on MySQL database connection, there will be a page presented informing about problem on establishing database connection. A page that we want to avoid. The worst thing is that when this ‘temporary’ page is indexed by search engines.
Reading what Derek Punsalan mentioned about custom error database connection page, his updated tutorial is very interesting. I mean, we (actually) can modify that error page into something better. In short, to have a custom page for database connection error page, just create a file called
db-error.php and put it under your
/wp-content/ directory. That’s it.
I made one. Here are few things I had in mind when I built it (I am using WordPress 2.5 right now).
- I do not want to tell (exclusively) about the database problem.
- But, I want to tell visitors that there is something does not run well.
- I want to keep them informed about this site. So, if search engines/other sites send people to my site — but it is not available — they know that actually they come to a right place.
- The page should not call any database connection (of course!).
- Lastly, I want to have a better page.
Anyway, the error message will be shown on a current accessed page. If they’re at the front page, they will have a same page when open a permalink or archive page. To see what happened when this site has a database connection problem, look at the screenshot. Of course, I hope that I do not to display this page.
If you want to use my
db-error.php, I’ve uploaded the template file so that you can customize it. Download now (2 Kb).