Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

sqlsrv_num_rows(3) [php man page]

SQLSRV_NUM_ROWS(3)														SQLSRV_NUM_ROWS(3)

sqlsrv_num_rows - Retrieves the number of rows in a result set

SYNOPSIS
mixed sqlsrv_num_rows (resource $stmt) DESCRIPTION
Retrieves the number of rows in a result set. This function requires that the statment resource be created with a static or keyset cursor. For more information, see sqlsrv_query(3), sqlsrv_prepare(3), or Specifying a Cursor Type and Selecting Rows in the Microsoft SQLSRV docu- mentation. PARAMETERS
o $stmt - The statement for which the row count is returned. The statment resource must be created with a static or keyset cursor. For more information, see sqlsrv_query(3), sqlsrv_prepare(3), or Specifying a Cursor Type and Selecting Rows in the Microsoft SQLSRV documentation. RETURN VALUES
Returns the number of rows retrieved on success and FALSE if an error occurred. If a forward cursor (the default) or dynamic cursor is used, FALSE is returned. EXAMPLES
Example #1 sqlsrv_num_rows(3) example <?php $server = "serverNamesqlexpress"; $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; ?> SEE ALSO
sqlsrv_has_rows(3), sqlsrv_rows_affected(3). PHP Documentation Group SQLSRV_NUM_ROWS(3)

Check Out this Related Man Page

SQLSRV_FETCH_ARRAY(3)													     SQLSRV_FETCH_ARRAY(3)

sqlsrv_fetch_array - Returns a row as an array

SYNOPSIS
array sqlsrv_fetch_array (resource $stmt, [int $fetchType], [int $row], [int $offset]) DESCRIPTION
Returns the next available row of data as an associative array, a numeric array, or both (the default). PARAMETERS
o $stmt - A statement resource returned by sqlsrv_query or sqlsrv_prepare. o $fetchType - A predefined constant specifying the type of array to return. Possible values are SQLSRV_FETCH_ASSOC, SQLSRV_FETCH_NUMERIC, and SQLSRV_FETCH_BOTH (the default). A fetch type of SQLSRV_FETCH_ASSOC should not be used when consuming a result set with multiple columns of the same name. o $row - Specifies the row to access in a result set that uses a scrollable cursor. Possible values are SQLSRV_SCROLL_NEXT, SQL- SRV_SCROLL_PRIOR, SQLSRV_SCROLL_FIRST, SQLSRV_SCROLL_LAST, SQLSRV_SCROLL_ABSOLUTE and, SQLSRV_SCROLL_RELATIVE (the default). When this parameter is specified, the $fetchType must be explicitly defined. o $offset - Specifies the row to be accessed if the row parameter is set to SQLSRV_SCROLL_ABSOLUTE or SQLSRV_SCROLL_RELATIVE. Note that the first row in a result set has index 0. RETURN VALUES
Returns an array on success, NULL if there are no more rows to return, and FALSE if an error occurs. EXAMPLES
Example #1 Retrieving an associative array. <?php $serverName = "serverNameinstanceName"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo ); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "SELECT FirstName, LastName FROM SomeTable"; $stmt = sqlsrv_query( $conn, $sql ); if( $stmt === false) { die( print_r( sqlsrv_errors(), true) ); } while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) { echo $row['LastName'].", ".$row['FirstName']."<br />"; } sqlsrv_free_stmt( $stmt); ?> Example #2 Retrieving a numeric array. <?php $serverName = "serverNameinstanceName"; $connectionInfo = array( "Database"=>"dbName", "UID"=>"username", "PWD"=>"password"); $conn = sqlsrv_connect( $serverName, $connectionInfo ); if( $conn === false ) { die( print_r( sqlsrv_errors(), true)); } $sql = "SELECT FirstName, LastName FROM SomeTable"; $stmt = sqlsrv_query( $conn, $sql ); if( $stmt === false) { die( print_r( sqlsrv_errors(), true) ); } while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_NUMERIC) ) { echo $row[0].", ".$row[1]."<br />"; } sqlsrv_free_stmt( $stmt); ?> NOTES
Not specifying the $fetchType or explicity using the SQLSRV_FETCH_TYPE constant in the examples above will return an array that has both associative and numeric keys. If more than one column is returned with the same name, the last column will take precedence. To avoid field name collisions, use aliases. If a column with no name is returned, the associative key for the array element will be an empty string (""). SEE ALSO
sqlsrv_connect(3), sqlsrv_query(3), sqlsrv_errors(3), sqlsrv_fetch(3). PHP Documentation Group SQLSRV_FETCH_ARRAY(3)
Man Page