sqlsrv_num_rows
Reports the number of rows in a result set.
Syntax
sqlsrv_num_rows( resource $stmt )
Parameters
$stmt: The result set for which to count the rows.
Return Value
false if there was an error calculating the number of rows. Otherwise, returns the number of rows in the result set.
Remarks
sqlsrv_num_rows requires a static or keyset cursor, and will return false if you use a forward cursor or a dynamic cursor. (A forward cursor is the default.) For more information about cursors, see sqlsrv_query and Specifying a Cursor Type and Selecting Rows.
Example
<?php
$server = "server_name";
$conn = sqlsrv_connect( $server, array( 'Database' => 'Northwind' ) );
$stmt = sqlsrv_query( $conn, "select * from orders where CustomerID = 'VINET'" , array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
$row_count = sqlsrv_num_rows( $stmt );
if ($row_count === false)
echo "\nerror\n";
else if ($row_count >=0)
echo "\n$row_count\n";
?>
See Also
Other Resources
SQLSRV Driver API Reference (Microsoft Drivers for PHP for SQL Server)