Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit a4c8a47

Browse files
authored
Merge pull request #9993 from david-puglielli/cursor-doc-fix
Fixed PDO cursor documentation
2 parents 89dcad7 + c9bcbbe commit a4c8a47

4 files changed

Lines changed: 205 additions & 206 deletions

File tree

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Cursor Types (PDO_SQLSRV Driver) | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "01/19/2017"
4+
ms.date: "04/22/2019"
55
ms.prod: sql
66
ms.prod_service: connectivity
77
ms.reviewer: ""
@@ -15,78 +15,78 @@ manager: craigg
1515
# Cursor Types (PDO_SQLSRV Driver)
1616
[!INCLUDE[Driver_PHP_Download](../../includes/driver_php_download.md)]
1717

18-
The PDO_SQLSRV driver lets you create scrollable result sets with one of several cursors.
19-
20-
For information on how to specify a cursor using the PDO_SQLSRV driver, and for code samples, see [PDO::prepare](../../connect/php/pdo-prepare.md).
21-
22-
## PDO_SQLSRV and Server-Side Cursors
23-
Prior to version 3.0 of the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)], the PDO_SQLSRV driver allowed you to create a result set with a server-side forward-only or static cursor. Beginning in version 3.0 of the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)], keyset and dynamic cursors are also available.
24-
25-
You can indicate the type of server-side cursor by using PDO::prepare or PDOStatement::setAttribute to select either cursor type:
26-
27-
- PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY
28-
29-
- PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL
30-
31-
You can request a keyset or dynamic cursor by specifying PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL and then pass the appropriate value to PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE. Possible values that you can pass to PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE are:
32-
33-
- PDO::SQLSRV_CURSOR_BUFFERED
34-
35-
- PDO::SQLSRV_CURSOR_DYNAMIC
36-
37-
- PDO::SQLSRV_CURSOR_KEYSET_DRIVEN
38-
39-
- PDO::SQLSRV_CURSOR_STATIC
40-
41-
## PDO_SQLSRV and Client-Side Cursors
42-
Client-side cursors were added in version 3.0 of the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)] that allows you to cache an entire result set in memory. One advantage is that row count is available after a query is executed.
43-
44-
Client-side cursors should be used for small- to medium-sized result sets. Large result sets should use server-side cursors.
45-
46-
A query will return false if the buffer is not large enough to hold an entire result set when using a client-side cursor. You can increase the buffer size up to the PHP memory limit.
47-
48-
You can configure the size of the buffer that holds the result set with the PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE attribute of [PDO::setAttribute](../../connect/php/pdo-setattribute.md) or [PDOStatement::setAttribute](../../connect/php/pdostatement-setattribute.md). You can also set the maximum buffer size in the php.ini file with pdo_sqlsrv.client_buffer_max_kb_size (for example, pdo_sqlsrv.client_buffer_max_kb_size = 1024).
49-
50-
You indicate that you want a client-side cursor by using PDO::prepare or PDOStatement::setAttribute and select the PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL cursor type. You then specify PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED.
51-
52-
```
53-
<?php
54-
$database = "AdventureWorks";
55-
$server = "(local)";
56-
$conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", "");
57-
58-
$query = "select * from Person.ContactType";
59-
$stmt = $conn->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
60-
$stmt->execute();
61-
print $stmt->rowCount();
62-
63-
echo "\n";
64-
65-
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
66-
print "$row[Name]\n";
67-
}
68-
echo "\n..\n";
69-
70-
$row = $stmt->fetch( PDO::FETCH_BOTH, PDO::FETCH_ORI_FIRST );
71-
print_r($row);
72-
73-
$row = $stmt->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_REL, 1 );
74-
print "$row[Name]\n";
75-
76-
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT );
77-
print "$row[1]\n";
78-
79-
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR );
80-
print "$row[1]..\n";
81-
82-
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, 0 );
83-
print_r($row);
84-
85-
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_LAST );
86-
print_r($row);
87-
?>
88-
```
89-
90-
## See Also
91-
[Specifying a Cursor Type and Selecting Rows](../../connect/php/specifying-a-cursor-type-and-selecting-rows.md)
92-
18+
The PDO_SQLSRV driver lets you create scrollable result sets with one of several cursors.
19+
20+
For information on how to specify a cursor using the PDO_SQLSRV driver, and for code samples, see [PDO::prepare](../../connect/php/pdo-prepare.md).
21+
22+
## PDO_SQLSRV and Server-Side Cursors
23+
Prior to version 3.0 of the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)], the PDO_SQLSRV driver allowed you to create a result set with a server-side forward-only or static cursor. Beginning in version 3.0 of the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)], keyset and dynamic cursors are also available.
24+
25+
You can indicate the type of server-side cursor by using [PDO::prepare](../../connect/php/pdo-prepare.md) to select one of the following cursor types:
26+
27+
- `PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY`
28+
29+
- `PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL`
30+
31+
You can request a dynamic, static, or keyset cursor by specifying `PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL` and then passing the appropriate value to `PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE`. Possible values that you can pass to `PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE` for server-side cursors are:
32+
33+
- `PDO::SQLSRV_CURSOR_DYNAMIC`
34+
35+
- `PDO::SQLSRV_CURSOR_STATIC`
36+
37+
- `PDO::SQLSRV_CURSOR_KEYSET_DRIVEN`
38+
39+
## PDO_SQLSRV and Client-Side Cursors
40+
Client-side cursors were added in version 3.0 of the [!INCLUDE[ssDriverPHP](../../includes/ssdriverphp_md.md)] and allow you to cache an entire result set in memory. One advantage is that the row count is available after a query is executed.
41+
42+
Client-side cursors should be used for small- to medium-sized result sets. Large result sets should use server-side cursors.
43+
44+
A query will return false if the buffer is not large enough to hold an entire result set when using a client-side cursor. You can increase the buffer size up to the PHP memory limit.
45+
46+
You can configure the size of the buffer that holds the result set with the `PDO::SQLSRV_ATTR_CLIENT_BUFFER_MAX_KB_SIZE` attribute of [PDO::setAttribute](../../connect/php/pdo-setattribute.md) or [PDOStatement::setAttribute](../../connect/php/pdostatement-setattribute.md). You can also set the maximum buffer size in the php.ini file with pdo_sqlsrv.client_buffer_max_kb_size (for example, pdo_sqlsrv.client_buffer_max_kb_size = 1024).
47+
48+
You can request a client-side cursor by using [PDO::prepare](../../connect/php/pdo-prepare.md), specifying the `PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL` cursor type, and then specifying `PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED`.
49+
50+
## Example
51+
The following example shows how to specify a buffered cursor.
52+
```
53+
<?php
54+
$database = "AdventureWorks";
55+
$server = "(local)";
56+
$conn = new PDO( "sqlsrv:server=$server ; Database = $database", "", "");
57+
58+
$query = "select * from Person.ContactType";
59+
$stmt = $conn->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
60+
$stmt->execute();
61+
print $stmt->rowCount();
62+
63+
echo "\n";
64+
65+
while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
66+
print "$row[Name]\n";
67+
}
68+
echo "\n..\n";
69+
70+
$row = $stmt->fetch( PDO::FETCH_BOTH, PDO::FETCH_ORI_FIRST );
71+
print_r($row);
72+
73+
$row = $stmt->fetch( PDO::FETCH_ASSOC, PDO::FETCH_ORI_REL, 1 );
74+
print "$row[Name]\n";
75+
76+
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT );
77+
print "$row[1]\n";
78+
79+
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR );
80+
print "$row[1]..\n";
81+
82+
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, 0 );
83+
print_r($row);
84+
85+
$row = $stmt->fetch( PDO::FETCH_NUM, PDO::FETCH_ORI_LAST );
86+
print_r($row);
87+
?>
88+
```
89+
90+
## See Also
91+
[Specifying a Cursor Type and Selecting Rows](../../connect/php/specifying-a-cursor-type-and-selecting-rows.md)
92+

0 commit comments

Comments
 (0)