sqlsrv_fetch

(No version information available, might only be in Git)

sqlsrv_fetchMakes the next row in a result set available for reading

说明

sqlsrv_fetch ( resource $stmt [, int $row [, int $offset ]] ) : mixed

Makes the next row in a result set available for reading. Use sqlsrv_get_field() to read the fields of the row.

参数

stmt

A statement resource created by executing sqlsrv_query() or sqlsrv_execute().

row

The row to be accessed. This parameter can only be used if the specified statement was prepared with a scrollable cursor. In that case, this parameter can take on one of the following values:

  • SQLSRV_SCROLL_NEXT
  • SQLSRV_SCROLL_PRIOR
  • SQLSRV_SCROLL_FIRST
  • SQLSRV_SCROLL_LAST
  • SQLSRV_SCROLL_ABSOLUTE
  • SQLSRV_SCROLL_RELATIVE

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.

返回值

Returns TRUE if the next row of a result set was successfully retrieved, FALSE if an error occurs, and NULL if there are no more rows in the result set.

范例

Example #1 sqlsrv_fetch() example

The following example demonstrates how to retrieve a row with sqlsrv_fetch() and get the row fields with sqlsrv_get_field().

<?php
$serverName 
"serverName\sqlexpress";
$connectionInfo = array( "Database"=>"dbName""UID"=>"username""PWD"=>"password");
$conn sqlsrv_connect$serverName$connectionInfo);
if( 
$conn === false ) {
     die( 
print_rsqlsrv_errors(), true));
}

$sql "SELECT Name, Comment 
        FROM Table_1
        WHERE ReviewID=1"
;
$stmt sqlsrv_query$conn$sql);
if( 
$stmt === false ) {
     die( 
print_rsqlsrv_errors(), true));
}

// Make the first (and in this case, only) row of the result set available for reading.
if( sqlsrv_fetch$stmt ) === false) {
     die( 
print_rsqlsrv_errors(), true));
}

// Get the row fields. Field indices start at 0 and must be retrieved in order.
// Retrieving row fields by name is not supported by sqlsrv_get_field.
$name sqlsrv_get_field$stmt0);
echo 
"$name: ";

$comment sqlsrv_get_field$stmt1);
echo 
$comment;
?>

参见

相关文章
php cubrid 函数 fetch the next row from a result setphp ibm db2 函数 returns an array indexed by column position representing a row in a result setphp ibm db2 函数 returns an array indexed by column name representing a row in a result setphp ibm db2 函数 returns an array indexed by both column name and position representing a row in a result setphp ibm db2 函数 sets the result set pointer to the next row or requested rowphp ibm db2 函数 requests the next result set from a stored procedurephp ibm db2 函数 returns a result set listing the unique row identifier columns for a tablephp maxdb 函数 returns the lengths of the columns of the current row in the result setphp maxdb 函数 returns the current row of a result set as an objectphp maxdb 函数 seeks to an arbitray row in statement result setphp oci8 函数 fetches the next row into result bufferphp sqlite 函数 fetches a column from the current row of a result setphp sqlite 函数 fetches the next row from a result set as an arrayphp sqlite 函数 fetches the next row from a result set as an objectphp sqlite 函数 seek to the previous row number of a result setphp sqlite 函数 seek to a particular row number of a buffered result setphp sqlsrv 函数 retrieves the next row of data in a result set as an objectphp sqlsrv 函数 makes the next row in a result set available for readingphp sqlsrv 函数 makes the next result of the specified statement activephp sqlsrv 函数 retrieves the number of rows in a result set
关注编程学问公众号