xref: /PHP-8.3/ext/pdo_pgsql/tests/bug68371.phpt (revision b3331644)
1--TEST--
2PDO PgSQL Bug #38671 (PDO#getAttribute() cannot be called with platform-specific attribute names)
3--EXTENSIONS--
4pdo
5pdo_pgsql
6--SKIPIF--
7<?php
8require __DIR__ . '/config.inc';
9require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
10PDOTest::skip();
11?>
12--FILE--
13<?php
14
15require __DIR__ . '/../../../ext/pdo/tests/pdo_test.inc';
16$pdo = PDOTest::test_factory(__DIR__ . '/common.phpt');
17$pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
18
19$attrs = array(
20    // Extensive test: default value and set+get values
21    PDO::ATTR_EMULATE_PREPARES			=> array(null, true, false),
22    PDO::PGSQL_ATTR_DISABLE_PREPARES	=> array(null, true, false),
23
24    // Just test the default
25    PDO::ATTR_AUTOCOMMIT			=> array(null),
26    PDO::ATTR_PREFETCH				=> array(null),
27    PDO::ATTR_TIMEOUT				=> array(null),
28    PDO::ATTR_ERRMODE				=> array(null),
29    PDO::ATTR_SERVER_VERSION		=> array(null),
30    PDO::ATTR_CLIENT_VERSION		=> array(null),
31    PDO::ATTR_SERVER_INFO			=> array(null),
32    PDO::ATTR_CONNECTION_STATUS		=> array(null),
33    PDO::ATTR_CASE					=> array(null),
34    PDO::ATTR_CURSOR_NAME			=> array(null),
35    PDO::ATTR_CURSOR				=> array(null),
36    PDO::ATTR_ORACLE_NULLS			=> array(null),
37    PDO::ATTR_PERSISTENT			=> array(null),
38    PDO::ATTR_STATEMENT_CLASS		=> array(null),
39    PDO::ATTR_FETCH_TABLE_NAMES		=> array(null),
40    PDO::ATTR_FETCH_CATALOG_NAMES	=> array(null),
41    PDO::ATTR_DRIVER_NAME			=> array(null),
42    PDO::ATTR_STRINGIFY_FETCHES		=> array(null),
43    PDO::ATTR_MAX_COLUMN_LEN		=> array(null),
44    PDO::ATTR_DEFAULT_FETCH_MODE	=> array(null),
45);
46
47foreach ($attrs as $a => $vals) {
48    foreach ($vals as $v) {
49        try {
50            if (!isset($v)) {
51                var_dump($pdo->getAttribute($a));
52            } else {
53                $pdo->setAttribute($a, $v);
54                if ($pdo->getAttribute($a) === $v) {
55                    echo "OK\n";
56                } else {
57                    throw new \Exception('KO');
58                }
59            }
60        } catch (\Exception $e) {
61            if ($e->getCode() == 'IM001') {
62                echo "ERR\n";
63            } else {
64                echo "ERR {$e->getMessage()}\n";
65            }
66        }
67    }
68}
69
70?>
71--EXPECTF--
72bool(false)
73OK
74OK
75bool(false)
76OK
77OK
78ERR
79ERR
80ERR
81int(2)
82string(%d) "%s"
83string(%d) "%s"
84string(%d) "%s"
85string(31) "%s"
86int(2)
87ERR
88ERR
89int(0)
90bool(false)
91array(1) {
92  [0]=>
93  string(12) "PDOStatement"
94}
95ERR
96ERR
97string(5) "pgsql"
98bool(true)
99ERR
100int(4)
101