I'm writing a function that queries my database, and if the mysql query errors out for some reason, I'd like my function to return a value (in this case -1) indicating query failure, rather than dying out of the whole script.
Usually I just use this construct:
$result = mysql_query($sql) or die( [some error information] );
But in this case I don't want to die, but I do need to break out of the function and have some way to tell the calling function that something went wrong, while still being able to manually check the logs for the source of the error. Is there a way to do this? The semi-pseudocode would look something like:
$result = mysql_query($sql) or {
error_log( [some error information] );
return -1;
}
But I've tried a couple variations on that and (as one might expect) they don't work.
Any suggestions? Thanks.