PHP- mysqli->num_rows 总是 returns 0,准备语句

PHP- mysqli->num_rows always returns 0, Prepared statements

首先,我想告诉大家,我已经解决了 ALL DUPLICATE 个问题。并尝试了那里建议的更改。

到目前为止,我已经尝试将 num_rows 更改为 num_rows() 并使用 store_result(); 并使用 affected_rows().

也在 execute()

之后调用 store_result();

我想可能还有其他我想不通的问题

$conn->autocommit(false);   
if ($sucess){
    $stmt2 = $conn->prepare("UPDATE e_eventqueue SET e_urlfil=? WHERE e_id=? 
AND u_id=?");
    $stmt2->bind_param("iis",$e_urlfil,$e_id,$u_id);

    if($stmt2->execute()){
         $stmt2->store_result();
        echo "true";
        echo $stmt2->num_rows;  // <- this always return 0 even when its not
        $stmt2->close();
        $conn->commit();
    }
 else{
      $conn->rollback();
     echo "rollback";
  }

}

如上评论所述,查看文档:

http://php.net/manual/mysqli-stmt.affected-rows.php

Returns the total number of rows changed, deleted, or inserted by the last executed statement

http://php.net/manual/mysqli-stmt.num-rows.php

Return the number of rows in statements result set

1st : 用于更新查询您需要检查 affected_rows 。不是 num_rows

2nd : 像这样执行检查后 $row_count= $stmt2->affected_rows; 如果查询成功执行但数据没有变化意味着它将 return 0 .

if($stmt2->execute()){

    echo $stmt2->affected_rows; 
 }

Affected_rows :

Affected_rows 用于 insert,update,delete

Num_rows :

Num_rows 用于 select