Skip to content

Latest commit

 

History

History
83 lines (62 loc) · 4.15 KB

File metadata and controls

83 lines (62 loc) · 4.15 KB
title Retrieving Data | Microsoft Docs
ms.custom
ms.date 01/19/2017
ms.prod sql-non-specified
ms.reviewer
ms.suite
ms.technology
drivers
ms.tgt_pltfrm
ms.topic article
ms.assetid 3414992c-61c0-4e7d-b509-72517e52c1bb
caps.latest.revision 42
author MightyPen
ms.author genemi
manager jhubbard

Retrieving Data

[!INCLUDEDriver_PHP_Download]

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

SQLSRV Driver

The SQLSRV driver of the [!INCLUDEssDriverPHP] 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 [!INCLUDEssDriverPHP], you can use sqlsrv_has_rows to see if a result set has rows.

PDO_SQLSRV Driver

The PDO_SQLSRV driver of the [!INCLUDEssDriverPHP] 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 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.

Related Sections

How to: Specify PHP Data Types

See Also

Programming Guide for PHP SQL Driver Retrieving Data