Bewerken

Delen via


Retrieving Data

Download PHP driver

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

SQLSRV Driver

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

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.

PDO_SQLSRV Driver

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.

In This Section

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.
How to: Retrieve Date and Time Types as Strings Using the SQLSRV Driver Describes how to retrieve date and time types as strings using the SQLSRV driver.
How to: Retrieve Date and Time Types as PHP Datetime Objects Using the PDO_SQLSRV Driver Describes how to retrieve date and time types as objects using the PDO_SQLSRV driver.
Formatting decimal strings with SQLSRV Driver Demonstrates how to format decimal or money values using the SQLSRV driver.
Formatting decimal strings with PDO_SQLSRV Driver Demonstrates how to format decimal or money values using the PDO_SQLSRV driver.

How to: Specify PHP Data Types

See Also

Programming Guide for the Microsoft Drivers for PHP for SQL Server

Retrieving Data