xref: /PHP-8.1/ext/pdo/tests/bug_44861.phpt (revision 74859783)
1--TEST--
2PDO Common: Bug #44861 (scrollable cursor don't work with pgsql)
3--EXTENSIONS--
4pdo
5--SKIPIF--
6<?php
7$dir = getenv('REDIR_TEST_DIR');
8if (false == $dir) die('skip no driver');
9$allowed = array('oci', 'pgsql');
10$ok = false;
11foreach ($allowed as $driver) {
12    if (!strncasecmp(getenv('PDOTEST_DSN'), $driver, strlen($driver))) {
13        $ok = true;
14    }
15}
16if (!$ok) {
17    die("skip Scrollable cursors not supported");
18}
19require_once $dir . 'pdo_test.inc';
20PDOTest::skip();
21?>
22--FILE--
23<?php
24if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
25require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
26$db = PDOTest::factory();
27
28$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
29
30if ($db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci') {
31    $from = 'FROM DUAL';
32    $ob = '1';
33} else {
34    $from = '';
35    $ob = 'r';
36}
37
38$query = "SELECT 'row1' AS r $from UNION SELECT 'row2' $from UNION SELECT 'row3' $from UNION SELECT 'row4' $from ORDER BY $ob";
39$aParams = array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL);
40
41$res = $db->prepare($query, $aParams);
42$res->execute();
43var_dump($res->fetchColumn());
44var_dump($res->fetchColumn());
45var_dump($res->fetchColumn());
46var_dump($res->fetchColumn());
47var_dump($res->fetchColumn());
48
49var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_ABS, 3));
50var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_PRIOR));
51var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_FIRST));
52var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST));
53var_dump($res->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_REL, -1));
54
55var_dump($res->fetchAll(PDO::FETCH_ASSOC));
56
57// Test binding params via emulated prepared query
58$res = $db->prepare("SELECT ? $from", $aParams);
59$res->execute(array("it's working"));
60var_dump($res->fetch(PDO::FETCH_NUM));
61
62
63// Test bug #48188, trying to execute again
64$res->execute(array("try again"));
65var_dump($res->fetchColumn());
66var_dump($res->fetchColumn());
67
68?>
69--EXPECT--
70string(4) "row1"
71string(4) "row2"
72string(4) "row3"
73string(4) "row4"
74bool(false)
75array(1) {
76  [0]=>
77  string(4) "row3"
78}
79array(1) {
80  [0]=>
81  string(4) "row2"
82}
83array(1) {
84  [0]=>
85  string(4) "row1"
86}
87array(1) {
88  [0]=>
89  string(4) "row4"
90}
91array(1) {
92  [0]=>
93  string(4) "row3"
94}
95array(1) {
96  [0]=>
97  array(1) {
98    ["r"]=>
99    string(4) "row4"
100  }
101}
102array(1) {
103  [0]=>
104  string(12) "it's working"
105}
106string(9) "try again"
107bool(false)
108