Mark’s Site

Pensieve for coding and golf :-)

Downgrade Gracefully

By admin • May 7th, 2008 • Category: 2.1.4. User Interface Design

We often rely on external connections in our coding. One such example is a connection to our database. Others might be SOAP connections, or any external API like Facebook.

Do you know what happens to your code if the database becomes unavailable, or the external API just drops off the face of the net? I mean, you’ve taken the code examples from someone else that had “or die(’no database connection’)” …but have you actually tested what this does and how it looks to a user should this connection become unavailable?

The best thing you can do is provide incorrect database parameters to your website and sit back and just see what happens. Try an incorrect host, then try incorrect login details to the correct host. Then try the wrong database name. Try it all, and see how your application performs. You should always present your USER with a pleasant message, and not some PHP generated error message with half your page cut off from a loading problem. So either create a page dedicated to such situations where you can redirect to in these instances, or just make sure you present a friendly error message on the page where the problem occurred, ensuring the rest of the page design doesn’t get cut off unexpectedly thanks to the error that’s occurred.

Doing this is important for your users. If they see a bad error message instead of your site, they might not come back. And also importantly is the type of error messages you show in your coding. PHP fatal errors with databases might show your database name, and login details. We wouldn’t want to give a hacker the favour of all the hard work would we? So play smart and handle your errors!

admin is
Email this author | All posts by admin

Leave a Reply