Webmasters who have played WordPress should be familiar with the phrase “Error establishing a database connection”. When you see this sentence, the website may have been hung up for several hours-because WordPress will not automatically email you this error.
Fortunately, WordPress allows us to create a custom database error page, and we only need to create a db-error.php file in wp-content.
Benefits of customization
In this custom error page, we can do these three things:
Tell the search engine that this is just a temporary error;
Send an email to inform the webmaster;
Optimize page information, not just an ugly sentence;
Sample code
php
$protocol = $_SERVER['SERVER_PROTOCOL'];
if ( ! in_array( $protocol, array( 'HTTP/1.1', 'HTTP/2', 'HTTP/2.0' ) ) ) $protocol = 'HTTP/1.0';
header( "$protocol 503 Service Temporarily Unavailable" );
header( 'Status: 503 Service Temporarily Unavailable' );
header( 'Retry-After: 3600' );
Mail( 'webmaster@example.com',' Website is temporarily unavailable',' Error in establishing database connection');
? >
< title > the website is temporarily unavailable < /title >
< h1 > the website is temporarily unavailable < /h1 >
< p > the website is under maintenance, please visit later.
< p > contact the webmaster: < a href = "mailto: webmaster @ example.com" > webmaster @ example.com
If you are lazy …
If you are too lazy to do it yourself, you can also install the DB Error Customizer plug-in, which also provides the functions of email notification and custom page content.