{"id":627,"date":"2013-02-09T20:03:41","date_gmt":"2013-02-09T20:03:41","guid":{"rendered":"http:\/\/invisiblezero.net\/?p=322"},"modified":"2013-02-09T20:03:41","modified_gmt":"2013-02-09T20:03:41","slug":"wordpress-customize-your-database-connection-error-message","status":"publish","type":"post","link":"http:\/\/ndthanh.com\/wordpress-customize-your-database-connection-error-message\/","title":{"rendered":"WordPress – customize your database connection error message"},"content":{"rendered":"

Some time, your MySQL server die unexpectedly, you don’t have any plan for it and this is what you’ll get<\/p>\n

\"error-establishing-connection-database\"<\/p>\n

ugly huh ? i personally hate this error message a lot. so i decided to turn it to something better, make me feel comfortable and give me chances to fix this issue.<\/p>\n

<\/p>\n

if you look at wp-includes\/functions.php, line 2710, there’s a dead_db function<\/p>\n

\n\nfunction dead_db() {\nglobal $wpdb;\n\n\/\/ Load custom DB error template, if present.\nif ( file_exists( WP_CONTENT_DIR . '\/db-error.php' ) ) {\nrequire_once( WP_CONTENT_DIR . '\/db-error.php' );\ndie();\n}\n\n\/\/ If installing or in the admin, provide the verbose message.\nif ( defined('WP_INSTALLING') || defined('WP_ADMIN') )\nwp_die($wpdb->error);\n\n\/\/ Otherwise, be terse.\nstatus_header( 500 );\nnocache_headers();\nheader( 'Content-Type: text\/html; charset=utf-8' );\n\nwp_load_translations_early();\n?>\n<!DOCTYPE html>\n<html xmlns="http:\/\/www.w3.org\/1999\/xhtml"<?php if ( is_rtl() ) echo ' dir="rtl"'; ?>>\n<head>\n<meta http-equiv="Content-Type" content="text\/html; charset=utf-8" \/>\n<title><?php _e( 'Database Error' ); ?><\/title>\n\n<\/head>\n<body>\n<h1><?php _e( 'Error establishing a database connection' ); ?><\/h1>\n<\/body>\n<\/html>\n<?php\ndie();\n}\n\n<\/pre>\n

there it is, you can have a db error template for that ugly message. From here, what you need to do is creating your own message. this is mine :<\/p>\n

\n\n<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1.0 Strict\/\/EN"\n"http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-strict.dtd">\n\n<html xmlns="http:\/\/www.w3.org\/1999\/xhtml">\n<head>\n<title>Site under maintenance<\/title>\n<style type="text\/css">\nbody {\nbackground: #3C78B5;\nfont-family: sans-serif;\n}\n.content {\nposition: fixed;\ntop: 35%;\nleft: 50%;\nmargin-top: -100px;\nmargin-left: -300px;\nwidth: 600px;\nborder-radius: 5px;\npadding: 20px;\nbackground-color: #F8F8F6;\nbox-shadow: 0 0 5px #555555;\n}\n.para,.logo {\nheight : 100px;\ndisplay: table-cell;\nvertical-align: middle;\ntext-align: center;\n}\n.para {\nborder-right: 1px solid #D1D1D2;\nwidth: 50%;\n}\n.logo {\nwidth: 40%;\npadding-left: 15px;\n}\n<\/style>\n<\/head>\n\n<body>\n<div>\n<div>\nThis site is currently undergoing maintenance. Please check back shortly.\n<\/div>\n<div>\n<img src="\/blog-logo.png"\/>\n<\/div>\n<\/div>\n<\/body>\n\n<\/pre>\n

tadaaa!<\/p>\n

\"custom<\/p>\n","protected":false},"excerpt":{"rendered":"

Some time, your MySQL server die unexpectedly, you don’t have any plan for it and this is what you’ll get ugly huh ? i personally hate this error message a lot. so i decided to turn it to something better, make me feel comfortable and give me chances to fix this issue. if you look…<\/p>\n

Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[],"aioseo_notices":[],"views":5,"_links":{"self":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/627"}],"collection":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/comments?post=627"}],"version-history":[{"count":0,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/posts\/627\/revisions"}],"wp:attachment":[{"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/media?parent=627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/categories?post=627"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ndthanh.com\/wp-json\/wp\/v2\/tags?post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}