mysqli_result::$num_rows
mysqli_result::$num_rows
mysqli_num_rows
(PHP 5, PHP 7)
mysqli_result :: $ num_rows -- mysqli_num_rows — 获取结果中的行数
描述
面向对象的风格
int $mysqli_result->num_rows;
程序风格
int mysqli_num_rows ( mysqli_result $result )
返回结果集中的行数。
mysqli_num_rows()
的行为取决于是否使用缓冲或无缓冲的结果集。对于未缓冲的结果集,mysqli_num_rows()
将不会返回正确的行数,直到检索到结果中的所有行。
参数
`result`
仅过程风格:由mysqli_query(),mysqli_store_result()或mysqli_use_result()返回的结果集标识符。
返回值
返回结果集中的行数。
注意
:
例子
Example#1面向对象的风格
<?php
$mysqli = new mysqli("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("SELECT Code, Name FROM Country ORDER BY Name")) {
/* determine number of rows result set */
$row_cnt = $result->num_rows;
printf("Result set has %d rows.\n", $row_cnt
/* close result set */
$result->close(
}
/* close connection */
$mysqli->close(
?>
示例#2程序风格
<?php
$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
?>