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