Documentation Home
Connectors and APIs Manual
Download this Manual
PDF (US Ltr) - 5.3Mb
PDF (A4) - 5.3Mb


Connectors and APIs Manual  /  ...  /  mysqli_stmt::$num_rows, mysqli_stmt::num_rows, mysqli_stmt_num_rows

7.3.9.21 mysqli_stmt::$num_rows, mysqli_stmt::num_rows, mysqli_stmt_num_rows

Copyright 1997-2022 the PHP Documentation Group.

  • mysqli_stmt::$num_rows

    mysqli_stmt::num_rows

    mysqli_stmt_num_rows

    Returns the number of rows fetched from the server

Description

Object-oriented style

int|string mysqli_stmt->num_rows ;
public int|string mysqli_stmt::num_rows();

Procedural style

int|string mysqli_stmt_num_rows(mysqli_stmt statement);

Returns the number of rows buffered in the statement. This function will only work after mysqli_stmt_store_result is called to buffer the entire result set in the statement handle.

This function returns 0 unless all rows have been fetched from the server.

Parameters

statement

Procedural style only: A mysqli_stmt object returned by mysqli_stmt_init.

Return Values

An int representing the number of buffered rows. Returns 0 in unbuffered mode unless all rows have been fetched from the server.

Note

If the number of rows is greater than PHP_INT_MAX, the number will be returned as a string.

Examples

Example 7.98 Object-oriented style

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
$stmt = $mysqli->prepare($query);
$stmt->execute();
/* store the result in an internal buffer */
$stmt->store_result();
printf("Number of rows: %d.\n", $stmt->num_rows);

Example 7.99 Procedural style

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 20";
$stmt = mysqli_prepare($link, $query);
mysqli_stmt_execute($stmt);
/* store the result in an internal buffer */
mysqli_stmt_store_result($stmt);
printf("Number of rows: %d.\n", mysqli_stmt_num_rows($stmt));

The above examples will output:

Number of rows: 20.


See Also

mysqli_stmt_store_result
mysqli_stmt_affected_rows
mysqli_prepare