sqlsrv_fetch
sqlsrv_fetch
Makes the next row in a result set available for reading
mixed **sqlsrv_fetch** resource $stmt int $row int $offset
Makes the next row in a result set available for reading. Use
to read the fields of the row.
sqlsrv_get_field
stmt
A statement resource created by executing
or .
sqlsrv_query``sqlsrv_execute
rowThe 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:
offset
Specifies the row to be accessed if the row parameter is set to
or
. Note that the first row in
a result set has index 0.
SQLSRV_SCROLL_ABSOLUTE``SQLSRV_SCROLL_RELATIVE
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.
Voorbeeld: example
The following example demonstrates how to retrieve a row with
and get the row fields with
.
sqlsrv_fetch``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 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( $stmt, 0);
echo "$name: ";
$comment = sqlsrv_get_field( $stmt, 1);
echo $comment;
?>
sqlsrv_get_field``sqlsrv_fetch_array``sqlsrv_fetch_object