I'm using $mysqli->query all over the place without any sort of error checking or fall back if the query fails.
What's the simplest/cleanest method I can use to catch these ?
I'm thinking of a little function which can just display a friendly message and send me an email - I can write that but am not sure how to trigger/call it only when an error occurs? without adding heaps of if statements...
i.e I wrap them all like:
if($mysqli->开发者_StackOverflow中文版query($query)) blah } else { error }
That will really bloat my code...
Make your own database class that extends mysqli, and does the error catching/emailing when you call my_mysqli->doQuery()
:
class my_mysqli extends mysqli
{
function doQuery($query)
{
if($this->query($query)) return $blah } else { do error blah }
}
}
精彩评论