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