PHP mysqli_num_rows()函数的用法(附带实例)
当从数据表中查询数据时,mysqli_num_rows() 函数返回符合查询条件的记录行数,如果没有符合条件的记录,则返回 0。
mysqli_num_rows() 函数的语法格式如下:
该函数仅对 SELECT 语句有效,要取得被 INSERT、UPDATE 或者 DELETE 语句影响的行数目,则需要使用 mysqli_affected_rows() 函数。
【实例】使用 mysqli_num_rows() 函数统计数据表中的记录行数。

图:获取表中的记录行数
mysqli_num_rows() 函数的语法格式如下:
int mysqli_num_rows(resource result_set)参数“result_set”是由 mysqli_query() 函数返回的资源标识号(标识一个查询结果集)。
该函数仅对 SELECT 语句有效,要取得被 INSERT、UPDATE 或者 DELETE 语句影响的行数目,则需要使用 mysqli_affected_rows() 函数。
【实例】使用 mysqli_num_rows() 函数统计数据表中的记录行数。
<?php $db = @mysqli_connect("localhost","root","root") or die("连接失败, 无法连接到本地MySQL服务器!"); echo("已连接到MySQL服务器<br />"); mysqli_query($db,"set names utf8"); mysqli_select_db($db,"test"); $query=mysqli_query($db,"select * from student") or die("<br> 查询数据表“student”失败!"); $rows=mysqli_num_rows($query); echo "记录行数为".$rows; ?>运行结果如下图所示:

图:获取表中的记录行数