PHP mysqli_num_rows MySQLi 函数

定义和用法

mysqli_num_rows - 获取结果中的行数

版本支持

PHP4PHP5PHP7
不支持支持支持

语法

mysqli_num_rows ( mysqli_result $result )

返回结果集中的行数。 mysqli_num_rows的行为取决于是否使用缓冲的或未缓冲的结果集。 对于无缓冲的结果集,在检索到结果中的所有行之前,mysqli_num_rows不会返回正确的行数。

参数

参数必需的描述
result由 mysqli_query()mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识。

返回值

返回结果集中的行数。如果行数大于PHP_INT_MAX,则该数字将作为字符串返回。

示例

$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($result = mysqli_query($link, "SELECT Code, Name FROM Country ORDER BY Name")) {
/* determine number of rows result set */
$row_cnt = mysqli_num_rows($result);
printf("Result set has %d rows.\n", $row_cnt);
/* close result set */
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);


相关函数

mysqli_query() - 对数据库执行一次查询

mysqli_affected_rows() - 获取上一个MySQL操作中受影响的行数

mysqli_store_result() - 转移上一次查询返回的结果集

mysqli_use_result() - 启动结果集检索


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章