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