您需要
store_result()在访问
num_rows属性之前调用该方法。
来自对PHP手册文档的评论:
如果不使用
mysqli_stmt_store_result(),并在执行准备好的语句后立即调用此函数,则该函数通常将返回0,因为它无法知道结果集中有多少行,因为结果集尚未保存在内存中。mysqli_stmt_store_result()将结果集保存在内存中,因此您可以在执行语句并保存结果集后立即使用此功能。
您的代码应如下所示:
$stmt->execute();$stmt->store_result();$stmt->bind_result($id, $added, $title);while ($stmt->fetch()) { # some random output here...}$count = $stmt->num_rows;


