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