1--TEST--
2MySQL PDO->__construct(), libmysql only options
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once __DIR__ . '/inc/mysql_pdo_test.inc';
8MySQLPDOTest::skip();
9if (MySQLPDOTest::isPDOMySQLnd())
10    die("skip libmysql only options")
11?>
12--FILE--
13<?php
14    require_once __DIR__ . '/inc/mysql_pdo_test.inc';
15
16    function set_option_and_check($offset, $option, $value, $option_desc, $ignore_diff = false) {
17        $dsn = MySQLPDOTest::getDSN();
18        $user = PDO_MYSQL_TEST_USER;
19        $pass = PDO_MYSQL_TEST_PASS;
20
21        try {
22            $db = new PDO($dsn, $user, $pass, array($option => $value));
23            if (!is_object($db) || (!$ignore_diff && ($value !== ($tmp = @$db->getAttribute($option)))))
24                printf("[%03d] Expecting '%s'/%s got '%s'/%s' for options '%s'\n",
25                    $offset,
26                    $value, gettype($value),
27                    $tmp, gettype($tmp),
28                    $option_desc);
29        } catch (PDOException $e) {
30            echo "Failed to getAttribute() for $option_desc\n";
31        }
32    }
33
34    $dsn = MySQLPDOTest::getDSN();
35    $user = PDO_MYSQL_TEST_USER;
36    $pass = PDO_MYSQL_TEST_PASS;
37
38    $valid_options = [];
39    $valid_options[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE';
40    $valid_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'PDO::MYSQL_ATTR_INIT_COMMAND';
41    $valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE';
42    $valid_options[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = 'PDO::MYSQL_ATTR_READ_DEFAULT_GROUP';
43
44    $defaults[PDO::MYSQL_ATTR_MAX_BUFFER_SIZE] = 1048576;
45    /* TODO getAttribute() does not handle it */
46    $defaults[PDO::MYSQL_ATTR_INIT_COMMAND] = '';
47    $defaults[PDO::MYSQL_ATTR_READ_DEFAULT_FILE] = false;
48    $defaults[PDO::MYSQL_ATTR_READ_DEFAULT_GROUP] = false;
49
50    $db = new PDO($dsn, $user, $pass);
51    foreach ($valid_options as $option => $name) {
52        try {
53            $tmp = $db->getAttribute($option);
54            if ($tmp !== $defaults[$option])
55                printf("[001] Expecting default value for '%s' of '%s'/%s, getAttribute() reports setting '%s'/%s\n",
56                    $name, $defaults[$option], gettype($defaults[$option]),
57                    $tmp, gettype($tmp));
58        } catch (PDOException $e) {
59            echo "Failed to getAttribute() for $name\n";
60        }
61    }
62
63    set_option_and_check(26, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, true, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
64    set_option_and_check(27, PDO::MYSQL_ATTR_READ_DEFAULT_FILE, false, 'PDO::MYSQL_ATTR_READ_DEFAULT_FILE');
65
66    set_option_and_check(30, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, -1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE', true);
67    set_option_and_check(31, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, PHP_INT_MAX, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
68    set_option_and_check(32, PDO::MYSQL_ATTR_MAX_BUFFER_SIZE, 1, 'PDO::MYSQL_ATTR_MAX_BUFFER_SIZE');
69
70    print "done!\n";
71?>
72--EXPECT--
73Failed to getAttribute() for PDO::MYSQL_ATTR_INIT_COMMAND
74Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_FILE
75Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_GROUP
76Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_FILE
77Failed to getAttribute() for PDO::MYSQL_ATTR_READ_DEFAULT_FILE
78done!
79