例
返回结果集中的行数:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
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))
{
// Return the
number of rows in result set
$rowcount=mysqli_num_rows($result);
printf("Result set has %d
rows.\n",$rowcount);
// Free result
set
mysqli_free_result($result);
}
mysqli_close($con);
?>
定义和用法
所述mysqli_num_rows()函数返回一个结果集的行数。
句法
mysqli_num_rows( result ) ;
参数 | 描述 |
---|---|
result | 需要。 指定由返回的结果集标识符mysqli_query() mysqli_store_result()或mysqli_use_result() |
技术细节
返回值: | 返回结果集的行数 |
---|---|
PHP版本: | 5+ |
<PHP库MySQLi参考