Custom error page when connection to MySQL fails

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Post Reply
User avatar
Augustas
Forum Members
Forum Members
Posts: 241
Joined: Wed Oct 17, 2007 6:09 pm

Custom error page when connection to MySQL fails

Post by Augustas »

It would be nice to be able to cutomize somehow the error message that appears when the MySQL server is temporally down.

By default AdoDB library shows message like this:
Database Connection Failed
Error: Access denied for user 'root'@'localhost' (using password: NO) (1045)
Function Performed: CONNECT
Host/DB: localhost/cmsms_website
Database Type: mysql
Currently I am using this kind of trick:
1. I created a static /page_error.html page under my website's root.
2. I edited /lib/adodb.functions.php file in the following way:

FIND

Code: Select all

function adodb_error($dbtype, $function_performed, $error_number, $error_message, $host, $database, &$connection_obj)
{
AFTER ADD

Code: Select all

	include_once(dirname(__FILE__).'/../page_error.html');
	exit;
So now, whenever by some reasons MySQL server is down, the visitor sees my custom "page_error.html" instead of revealing to him the MySQL username and database name.
http://FollowTheRoad.com/ - living on the road...
http://www.kligys.com/ - asmeninis blog'as...
User avatar
blast2007
Power Poster
Power Poster
Posts: 508
Joined: Wed Aug 01, 2007 5:36 pm

Re: Custom error page when connection to MySQL fails

Post by blast2007 »

Augustas wrote: So now, whenever by some reasons MySQL server is down, the visitor sees my custom "page_error.html" instead of revealing to him the MySQL username and database name.
Thanks, nice trick, it should be added to CMSMS security wiki (and maybe to the core?)

Regards,
blast
Pierre M.

Re: Custom error page when connection to MySQL fails

Post by Pierre M. »

I have filed this as bug #2519 hoping your suggestion is followed.

Pierre
Pierre M.

Re: Custom error page when connection to MySQL fails

Post by Pierre M. »

Hello again,

there is response from Alby. Please see the followup http://dev.cmsmadesimple.org/tracker/?f ... group_id=6.

Pierre
jmcgin51
Power Poster
Power Poster
Posts: 1899
Joined: Mon Jun 12, 2006 9:02 pm

Re: Custom error page when connection to MySQL fails

Post by jmcgin51 »

Pierre - your link no longer works for some reason.

Here is the current link.
dev.cmsmadesimple.org/bug/view?id=2519

In a nutshell, place a file named "db_error.html" in the CMSMS root.  This file should contain whatever custom error you want the user to see in the event of an SQL error.  As long as this file exists, the "custom error" functionality is built-in to CMSMS out-of-the-box.  (No need for the edits noted in the posts above.)
Golf Gti

Re: Custom error page when connection to MySQL fails

Post by Golf Gti »

You do realize this is built into php?

all you have to do is create a db_error.html page with what ever you want it to say.
Post Reply

Return to “Tips and Tricks”