Export (0) Print
Expand All


Reports the number of rows in a result set.

sqlsrv_num_rows( resource $stmt )

$stmt: The result set for which to count the rows.

false if there was an error calculating the number of rows. Otherwise, returns the number of rows in the result set.

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.

   $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";
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft