1--TEST--
2PDO MySQL specific class constants
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7if (!extension_loaded('mysqli') && !extension_loaded('mysqlnd')) {
8    /* Need connection to detect library version */
9    require_once __DIR__ . '/inc/mysql_pdo_test.inc';
10    MySQLPDOTest::skip();
11}
12?>
13--FILE--
14<?php
15    require_once __DIR__ . '/inc/mysql_pdo_test.inc';
16
17    function get_client_version() {
18        if (extension_loaded('mysqli')) {
19            return mysqli_get_client_version();
20        }
21        /* XXX the MySQL client library version isn't exposed with any
22        constants, the single possibility is to use the PDO::getAttribute().
23        This however will fail with no connection. */
24        return MySQLPDOTest::getClientVersion(MySQLPDOTest::factory());
25    }
26
27    $expected = [
28        'MYSQL_ATTR_USE_BUFFERED_QUERY'	        	=> true,
29        'MYSQL_ATTR_LOCAL_INFILE'					=> true,
30        'MYSQL_ATTR_DIRECT_QUERY'					=> true,
31        'MYSQL_ATTR_FOUND_ROWS'						=> true,
32        'MYSQL_ATTR_IGNORE_SPACE'					=> true,
33        'MYSQL_ATTR_INIT_COMMAND'					=> true,
34        "MYSQL_ATTR_SSL_KEY"						=> true,
35        "MYSQL_ATTR_SSL_CERT"						=> true,
36        "MYSQL_ATTR_SSL_CA"							=> true,
37        "MYSQL_ATTR_SSL_CAPATH"						=> true,
38        "MYSQL_ATTR_SSL_CIPHER"						=> true,
39        "MYSQL_ATTR_COMPRESS"						=> true,
40        "MYSQL_ATTR_MULTI_STATEMENTS"				=> true,
41    ];
42
43    if (!MySQLPDOTest::isPDOMySQLnd()) {
44        $expected['MYSQL_ATTR_MAX_BUFFER_SIZE']			= true;
45        $expected['MYSQL_ATTR_READ_DEFAULT_FILE']		= true;
46        $expected['MYSQL_ATTR_READ_DEFAULT_GROUP']		= true;
47    }
48
49    if (extension_loaded('mysqlnd')) {
50        $expected['MYSQL_ATTR_SSL_VERIFY_SERVER_CERT']  = true;
51        $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY']		= true;
52    } else if (get_client_version() > 50605) {
53        $expected['MYSQL_ATTR_SERVER_PUBLIC_KEY']	= true;
54    }
55
56    if (MySQLPDOTest::isPDOMySQLnd() || get_client_version() >= 80021) {
57        $expected['MYSQL_ATTR_LOCAL_INFILE_DIRECTORY']	= true;
58    }
59
60    /*
61    TODO
62
63        MYSQLI_OPT_CONNECT_TIMEOUT != PDO::ATTR_TIMEOUT  (integer)
64    Sets the timeout value in seconds for communications with the database.
65        ^  Potential BUG, PDO::ATTR_TIMEOUT is used in pdo_mysql_handle_factory
66
67        MYSQLI_SET_CHARSET_NAME -> DSN/charset=<charset_name>
68        ^ Undocumented and pitfall for ext/mysqli users
69
70        Assorted mysqlnd settings missing
71    */
72    $ref = new ReflectionClass('PDO');
73    $constants = $ref->getConstants();
74    $values = [];
75
76    foreach ($constants as $name => $value)
77        if (substr($name, 0, 11) == 'MYSQL_ATTR_') {
78            if (!isset($values[$value]))
79                $values[$value] = [$name];
80            else
81                $values[$value][] = $name;
82
83            if (isset($expected[$name])) {
84                unset($expected[$name]);
85                unset($constants[$name]);
86            }
87
88        } else {
89            unset($constants[$name]);
90        }
91
92    if (!empty($constants)) {
93        printf("[001] Dumping list of unexpected constants\n");
94        var_dump($constants);
95    }
96
97    if (!empty($expected)) {
98        printf("[002] Dumping list of missing constants\n");
99        var_dump($expected);
100    }
101
102    if (!empty($values)) {
103        foreach ($values as $value => $constants) {
104            if (count($constants) > 1) {
105                printf("[003] Several constants share the same value '%s'\n", $value);
106                var_dump($constants);
107            }
108        }
109    }
110
111    print "done!";
112?>
113--EXPECT--
114done!
115