PHP Try and Catch for SQL Insert

前端 未结 9 987
南方客
南方客 2020-12-15 18:05

I have a page on my website (high traffic) that does an insert on every page load.

I am curious of the fastest and safest way to (catch an error) and continue if the

9条回答
  •  爱一瞬间的悲伤
    2020-12-15 18:23

    Checking the documentation shows that its returns false on an error. So use the return status rather than or die(). It will return false if it fails, which you can log (or whatever you want to do) and then continue.

    $rv = mysql_query("INSERT INTO redirects SET ua_string = '$ua_string'");
    if ( $rv === false ){
         //handle the error here
    }
    //page continues loading
    

提交回复
热议问题