I just got the "Unable to connect to database server" error message on one of my sites.

No big deal with the error, as it was just a short server glitch, and everything was back working again in a few seconds.

However, I didn't think the content of the error message was what I would want regular visitors to the site to see.

Apart from giving some details about my database (username and database server name), it gives links to installation and upgrade documentation.

Basically, it doesn't look too 'professional'.

So, is there anyway to customise this to something more suitable?

I know there are ways to customise the 403 and 404 error pages, but what about this one?

Comments

hausig’s picture

Hallo, I get the same error once in a while and would be very grateful for a hint how to customize this error page.

I've found a solution that works for now but is probably not a "clean" solution:
The error message gets built in database.mysql.inc. I just changed the text to what ever message is wanted instead of the original one.

This helps for now, but a cleaner solution would be nice (I mean without going into a main script). It would be also nice if somebody could give a list of reasons why the connection can fail on a shared host even if the site is not very bussy.

2houseplague’s picture

I could not find an answer to the question posed here, so I thought Id bump this old thread.

This really is a serious security problem.

http://profitlabinc.com

Sewdn’s picture

Hi,

This error keeps on recurring...
You say "once in a while", but in my experience it shows about every 5 page requests.

Instead of shwoing a different error, i'm looking for a sollution to avoid the error. What could be causing this mysql-connection problems? I never had any problems connecting to my databases, using my own PHP scripts of using the PEAR module DB or MDB2...

Do all Drupal users suffer from this connection problem?
Is this problem a Drupal specific problem, or can my configuration be optimized to stabilize my Drupal MySQL connection?

Thanks!

firebus’s picture

i agree that this is a security issue. no matter how helpful a message like this is to an untrained user, it shouldn't be displayed on a public site ever.

would it make sense to use the settings on error-reporting page to determine whether or not to display the information on this page?

2houseplague’s picture

includes/database.mysql.inc - the message is in there and and can be easily edited.

http://profitlabinc.com

wwwoliondorcom’s picture

Where is the message for drupal 6 ?

Hi,

The text is not in this file on Drupal 6, do you know where to edit it ?

Thanks.

ttripp’s picture

It's helpful to be able to edit the error message, but it would be *really* helpful to fix whatever the root problem is. Anyone have any ideas? I'm finding my site performance (it's a small site) to be really poor as well of late. I'm assuming the two problems are related...

noah@groups.drupal.org’s picture

There's a related thread at http://drupal.org/node/152673 .

wwwoliondorcom’s picture

Solution to customize Drupal 6 "Unable to connect to Mysql database" page ?

hi,

do you know what is the solution to customize the database error page on drupal 6 ?

Thanks.

kingandy’s picture

Unfortunately the db_connect() function can't run its text through the translation system (because it doesn't yet have a connection to the database, of course), so there doesn't seem to be a way to customise the text directly.

However, it does pass the generated text through to _db_error_page(), which eventually calls theme('maintenance_page'), which er .... doesn't exist in Drupal 6 ... but you may be able to still use it (?) if you base your code on the docs provided for Drupal 5. Since there's no danger of the $content being translated into something else, you could certainly use some kind of pattern matching at this level to switch the text to something else.

EDITED TO ADD: Oh there are some docs on Theming the Drupal 6 maintenance page. Go team.

++Andy