2015-08-19 15:23



Consider the following simple PHP code:

   $db=new mysqli('localhost', 'root','','apeirosto');            
   $query="UPDATE REQUESTS SET STATUS=1 where requestid=155"; 
   if (!($result)) {
     $message= "fail_update";   
     echo $message;
     $message= "success";   
     echo $message;

My secondary question:


plays the role of commit in DB?

My main question:

even if there is no row with PK requestid=155, $result returns true and the message I get is "success"... Why? How may I get an error message in such cases?

Thank you

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dqt20140129 dqt20140129 6年前

    The query method returns false only when there is an error in executing. When no changes happens, there is no error, so query returns something other than false.

    You can use affected_rows property to check any rows are updated. It returns number of changed rows after the query.

    More information:

    点赞 评论 复制链接分享