我真的厌倦了这个 num_rows
属性。首先,我在没有 store_result()
的情况下使用它,但它无法正常工作。然后我发现我应该将结果存储在本地以便找出记录数。有效。现在它再次停止工作。
当我检查属性 RequestedId
时,它确实返回了一个值。但是,num_rows
表示零
。我还缺少什么?
$query="select RequestedId from friend_request where RequestingId=?";
$stmt=$mysqli->stmt_init();
$stmt->prepare($query);
$stmt->bind_param('i',$requestinguserid);
$stmt->execute();
$stmt->bind_result($RequestedId);
$stmt->fetch();
$stmt->store_result();
if($stmt->num_rows > 0)
{
return $RequestedId;
}
else{
return 0;
}
最佳答案
从本页的解释来看:http://php.net/manual/en/mysqli-stmt.store-result.php
在获取之前需要调用store_result
函数。
$stmt->execute();
/* store result */
$stmt->store_result();
printf("Number of rows: %d.\n", $stmt->num_rows);
/* free result */
$stmt->free_result();
您应该能够在释放结果之前阅读结果。
关于php - num_rows 属性永远无法预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30170334/