I'm nearing completion of my first php development, and i'm starting to put error handling in place. Right now my error handling is like this
$result = mysql_query($query, getDbConnection()) or die("getImages select Failed!");
which means the user just sees a short and not at all helpful message if the database query fails. They shouldn't fail that often, but I have some reasonably complex SQL, there's a chance that the odd one could fail until the systems been shaken down.
Does anyone have a pattern for showing a nicer error page when something goes wrong? Right now what i'm thinking of doing is something like this:
$ERROR = (a constant of some kind);
function doDatabaseStuff() {
$result = mysql_query($query, getDbConnection());
if (!$result) {
return $ERROR;
}
$res = doDatabaseStuff();
if ($res == $ERROR) {
smarty->include("errorPage.tpl");
}
Would anyone care to comment on this before I get started on it? It's easy to change all my mysql code, they're all inside functions in 1-2 php scripts.
I must get around to adding logging soon too.
TIA for any ideas 🙂