xref: /php-src/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__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12require_once __DIR__ . '/inc/mysql_pdo_test.inc';
13$pdo = MySQLPDOTest::factory();
14$pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
15
16$attrs = [
17    // Extensive test: default value and set+get values
18    PDO::ATTR_EMULATE_PREPARES	    => array(null, true, false),
19    PDO::MYSQL_ATTR_DIRECT_QUERY	=> array(null, false, true),
20    PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => array(null, false, true),
21
22    // Just test the default
23    PDO::ATTR_AUTOCOMMIT			=> [null],
24    PDO::ATTR_PREFETCH				=> [null],
25    PDO::ATTR_TIMEOUT				=> [null],
26    PDO::ATTR_ERRMODE				=> [null],
27    PDO::ATTR_SERVER_VERSION		=> [null],
28    PDO::ATTR_CLIENT_VERSION		=> [null],
29    PDO::ATTR_SERVER_INFO			=> [null],
30    PDO::ATTR_CONNECTION_STATUS		=> [null],
31    PDO::ATTR_CASE					=> [null],
32    PDO::ATTR_CURSOR_NAME			=> [null],
33    PDO::ATTR_CURSOR				=> [null],
34    PDO::ATTR_ORACLE_NULLS			=> [null],
35    PDO::ATTR_PERSISTENT			=> [null],
36    PDO::ATTR_STATEMENT_CLASS		=> [null],
37    PDO::ATTR_FETCH_TABLE_NAMES		=> [null],
38    PDO::ATTR_FETCH_CATALOG_NAMES	=> [null],
39    PDO::ATTR_DRIVER_NAME			=> [null],
40    PDO::ATTR_STRINGIFY_FETCHES		=> [null],
41    PDO::ATTR_MAX_COLUMN_LEN		=> [null],
42    PDO::ATTR_DEFAULT_FETCH_MODE	=> [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(true)
71OK
72OK
73bool(false)
74OK
75OK
76bool(true)
77OK
78OK
79bool(true)
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}
96bool(false)
97ERR
98string(5) "mysql"
99bool(false)
100ERR
101int(4)
102