xref: /PHP-8.2/ext/pdo_mysql/tests/bug68371.phpt (revision b3331644)
1--TEST--
2PDO MySQL Bug #38671 (PDO#getAttribute() cannot be called with platform-specific attribute names)
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13$pdo = MySQLPDOTest::factory();
14$pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
15
16$attrs = array(
17    // Extensive test: default value and set+get values
18    PDO::ATTR_EMULATE_PREPARES		=> array(null, 1, 0),
19    PDO::MYSQL_ATTR_DIRECT_QUERY	=> array(null, 0, 1),
20    PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => array(null, 0, 1),
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--
70int(1)
71OK
72OK
73int(0)
74OK
75OK
76int(1)
77OK
78OK
79int(1)
80ERR
81ERR
82int(2)
83string(%d) "%s"
84string(%d) "%s"
85string(%d) "%s"
86string(%d) "%s"
87int(2)
88ERR
89ERR
90int(0)
91bool(false)
92array(1) {
93  [0]=>
94  string(12) "PDOStatement"
95}
96ERR
97ERR
98string(5) "mysql"
99bool(false)
100ERR
101int(4)
102