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