How to check if an UPDATE mysqli query is correctly executed?

后端 未结 4 1632
忘掉有多难
忘掉有多难 2020-12-04 01:40

Here is my case:

$sql = \'UPDATE user SET password = ? WHERE username = ? AND password = ?\';
if($stmt->prepare($sql)) {
    $stmt->bind_param(\'sss\',         


        
相关标签:
4条回答
  • 2020-12-04 02:10

    You need to use the affected_rows function of the MySQL extension you are using. This will return 0 if the query failed because no rows matched, -1 if an error occurred, or a positive number showing the number of rows that were changed.

    0 讨论(0)
  • 2020-12-04 02:18

    A query which updates no rows is NOT an error condition. It's simply a succesful query that didn't change anything. To see if an update actually did change anything, you have to use mysqli_affected_rows()

    0 讨论(0)
  • 2020-12-04 02:27

    Try use mysqli_affected_rows() to get the number of affected rows.

    0 讨论(0)
  • 2020-12-04 02:37
     mysqli_query($link, "UPDATE Language SET Status=1 WHERE Percentage > 50");
     printf("Affected rows (UPDATE): %d\n", mysqli_affected_rows($link));
    

    Try that.

    0 讨论(0)
提交回复
热议问题