Friday, June 14, 2024

how to count rows in sqlserver -->sqlsrv_num_rows

 Example #1 sqlsrv_num_rows() example

<?php
$server
= "serverName\sqlexpress";
$connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password" );
$conn = sqlsrv_connect( $server, $connectionInfo );

$sql = "SELECT * FROM Table_1";
$params = array();
$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$stmt = sqlsrv_query( $conn, $sql , $params, $options );

$row_count = sqlsrv_num_rows( $stmt );

if (
$row_count === false)
echo
"Error in retrieveing row count.";
else
echo
$row_count;
?>