AsyncMysqlQueryResult::numRows
The number of rows in the current result
public function numRows(): int;
This is particularly useful for SELECT
statements.
This is complementary to numRowsAffected()
as they might be the same
value, but if this was an INSERT
query, for example, then this might be
0, while numRowsAffected()
could be non-zero.
See the MySQL's mysql_num_rows() documentation for more information.
Returns
int
- The number of rows in the current result as anint
.
Examples
This example shows how to determine the number of rows returned from a given query using AsyncMysqlQueryResult::numRows
.
use \Hack\UserDocumentation\API\Examples\AsyncMysql\ConnectionInfo as CI;
async function connect(
\AsyncMysqlConnectionPool $pool,
): Awaitable<\AsyncMysqlConnection> {
return await $pool->connect(
CI::$host,
CI::$port,
CI::$db,
CI::$user,
CI::$passwd,
);
}
async function simple_query(): Awaitable<int> {
$pool = new \AsyncMysqlConnectionPool(darray[]);
$conn = await connect($pool);
$result = await $conn->query('SELECT name FROM test_table WHERE userID < 50');
$conn->close();
// How many rows did this query return?
return $result->numRows();
}
<<__EntryPoint>>
async function run(): Awaitable<void> {
$r = await simple_query();
\var_dump($r);
}
```.hhvm.expectf
int(%d)
```.example.hhvm.out
int(1)
```.skipif
await \Hack\UserDocumentation\API\Examples\AsyncMysql\skipif_async();