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() - 啓動結果集檢索


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