我在 php 中使用 mysqli_num_rows() 来计算查询行数,然后在 Docs 中使用我读到:
The behaviour of mysqli_num_rows() depends on whether buffered or unbuffered result sets are being used. For unbuffered result sets, mysqli_num_rows() will not return the correct number of rows until all the rows in the result have been retrieved
它们到底是什么意思?查询何时无缓冲以及何时缓冲?
谢谢。
最佳答案
示例
返回结果集中的行数:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
检查连接
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";
if ($result=mysqli_query($con,$sql))
{
返回结果集中的行数
$rowcount=mysqli_num_rows($result);
printf("Result set has %d rows.\n",$rowcount);
免费结果集
mysqli_free_result($result);
}
mysqli_close($con);
?>
关于php - php 中 num_rows() 的 mysql 行数可靠吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39009353/