just dying with a technical error message is not realy useful, at least for your end-users ; and you should design your site having them in mind.
A solution that's probably more useful to anyone would be to :
- Log the technical error message to a file, that you'll sometimes check
- Display a nice "oops, an error has occured" page to the end-user.
Still, if you really need this, you could :
- Concatenate both informations, to only have one string
- use an if/else-block ; which might make your code more easy to read.
A nice solution might be to use exceptions (semi-pseudo-code) :
Of course, this is considering you've defined the MySQLException
somewhere.
try {
// Do some stuff
if (!mysql_query(...)) {
throw new MySQLException(mysql_error());
}
// Some other stuff
} catch (MySQLException $e) {
// Deal with the MySQLException kind of Exception
// i.e. deal my SQL errors
// => Log to file
// + display a nice error page
} catch (Exception $e) {
// At least, if something in the try block
// might raise an Exception that's not a MySQLException
}
One nice thing with Exception is that all your code that deals with errors is at one place : there is no die
everywhere in the middle of your code