Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Retrieving Data

SQL Server 2008 R2

This topic and the topics in this section discuss how to retrieve data.

The SQLSRV driver of the Microsoft Drivers for PHP for SQL Server provides the following options for retrieving data from a result set:

Note Note

When you use any of the functions mentioned above, avoid null comparisons as the criterion for exiting loops. Because sqlsrv functions return false when an error occurs, the following code could result in an infinite loop upon an error in sqlsrv_fetch_array:

/* This code could result in an infinite loop. It is recommended that

you do NOT use null comparisons as the criterion for exiting loops,

as is done here. */

do{

$result = sqlsrv_fetch_array($stmt);

} while( !is_null($result));

If your query retrieves more than one result set, you can move to the next result set with sqlsrv_next_result.

Beginning in version 1.1 of the Microsoft Drivers for PHP for SQL Server, you can use sqlsrv_has_rows to see if a result set has rows.

The PDO_SQLSRV driver of the Microsoft Drivers for PHP for SQL Server provides the following options for retrieving data from a result set:

If your query retrieves more than one result set, you can move to the next result set with PDOStatement::nextRowset.

You can see how many rows are in a result set if you specify a scrollable cursor, and then call PDOStatement::rowCount.

PDO::prepare lets you specify a cursor type. Then, with PDOStatement::fetch you can select a row. See PDO::prepare for a sample and more information.

Topic

Description

Retrieving Data as a Stream

Provides an overview of how to stream data from the server, and provides links to specific use cases.

Using Directional Parameters

Describes how to use directional parameters when calling a stored procedure.

Specifying a Cursor Type and Selecting Rows

Demonstrates how to create a result set with rows that you can access in any order when using the SQLSRV driver.

How to: Retrieve Date and Time Type as Strings Using the SQLSRV Driver

Describes how to retrieve date and time types as strings.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.