开发者

Simple error checking with mysqli?

开发者 https://www.devze.com 2023-01-14 09:24 出处:网络
I\'m using $mysqli->query all over the place without any sort of error checking or fall back if the query fails.

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 }
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号