sqlsrv_fetch
(No version information available, might only be in Git)
sqlsrv_fetch — Makes the next row in a result set available for reading
Description
Makes the next row in a result set available for reading. Use sqlsrv_get_field() to read the fields of the row.
Parameters
-
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
orSQLSRV_SCROLL_RELATIVE
. Note that the first row in a result set has index 0.
Return Values
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.
Examples
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_r( sqlsrv_errors(), true));
}
$sql = "SELECT Name, Comment
FROM Table_1
WHERE ReviewID=1";
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_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_r( sqlsrv_errors(), true));
}
// Get the row fields. Field indeces 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( $stmt, 0);
echo "$name: ";
$comment = sqlsrv_get_field( $stmt, 1);
echo $comment;
?>
See Also
- sqlsrv_get_field() - Gets field data from the currently selected row
- sqlsrv_fetch_array() - Returns a row as an array
- sqlsrv_fetch_object() - Retrieves the next row of data in a result set as an object
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- Microsoft SQL Server Driver for PHP
- sqlsrv_begin_transaction
- sqlsrv_cancel
- sqlsrv_client_info
- sqlsrv_close
- sqlsrv_commit
- sqlsrv_configure
- sqlsrv_connect
- sqlsrv_errors
- sqlsrv_execute
- sqlsrv_fetch_array
- sqlsrv_fetch_object
- sqlsrv_fetch
- sqlsrv_field_metadata
- sqlsrv_free_stmt
- sqlsrv_get_config
- sqlsrv_get_field
- sqlsrv_has_rows
- sqlsrv_next_result
- sqlsrv_num_fields
- sqlsrv_num_rows
- sqlsrv_prepare
- sqlsrv_query
- sqlsrv_rollback
- sqlsrv_rows_affected
- sqlsrv_send_stream_data
- sqlsrv_server_info
Коментарии
404 Not Found