php - php 中 num_rows() 的 mysql 行数可靠吗?

标签 php mysql mysqli numbers rows

我在 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/

相关文章:

mysql - mysql 中多家酒店的房间可用性

php - 发布http ://localhost/MyApp/MyCon/customerCheck 500 (Internal Server Error)

php - 仅当数据不存在时才将数据从一个表插入到另一个表

php - 查询正常工作但在准备好的语句中不工作

PHP/mySQL - 在本地准备和绑定(bind)

php - *仅*在数据库表更改(添加行)时刷新 html 页面部分

php - 如何选择用户在 SQL 和 PHP 中关注的具有特定主题标签的所有帖子?

PHP 解析来自 SOAP 客户端的 SOAP XML 响应

php - MySQL 特定查询不起作用

php - Docker 无法安装 php mysql 扩展