1--TEST--
2MySQL PDO->getAttribute()
3--SKIPIF--
4<?php
5require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
6require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7MySQLPDOTest::skip();
8$db = MySQLPDOTest::factory();
9if (false == MySQLPDOTest::detect_transactional_mysql_engine($db))
10    die("skip Transactional engine not found");
11?>
12--FILE--
13<?php
14    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
15    $db = MySQLPDOTest::factory();
16    MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
17
18    function set_and_get($offset, $db, $attribute, $value) {
19
20        $value_type = gettype($value);
21        try {
22
23            if (!$db->setAttribute($attribute, $value)) {
24                printf("[%03d] Cannot set attribute '%s' to value '%s'\n",
25                    $offset, $attribute, var_export($tmp, true));
26                return false;
27            }
28
29            if (gettype($value) != $value_type) {
30                printf("[%03d] Call to PDO::setAttribute(int attribute, mixed value) has changed the type of value from %s to %s, test will not work properly\n",
31                    $offset, $value_type, gettype($value));
32                return false;
33            }
34
35            $tmp = $db->getAttribute($attribute);
36            if ($tmp !== $value) {
37                printf("[%03d] Attribute '%s' was set to '%s'/%s but getAttribute() reports '%s'/%s\n",
38                    $offset, $attribute, var_export($value, true), gettype($value), var_export($tmp, true), gettype($tmp));
39                return false;
40            }
41
42        } catch (PDOException $e) {
43            printf("[%03d] %s, [%s] %s\n",
44                $offset, $e->getMessage(),
45                $db->errorCode(), implode(' ', $db->errorInfo()));
46            return false;
47        }
48
49        return true;
50    }
51
52    set_and_get(1, $db, PDO::ATTR_AUTOCOMMIT, 1);
53/*
54    set_and_get(2, $db, PDO::ATTR_AUTOCOMMIT, 0);
55    set_and_get(3, $db, PDO::ATTR_AUTOCOMMIT, -1);
56    $obj = new stdClass();
57    set_and_get(4, $db, PDO::ATTR_AUTOCOMMIT, $obj);
58
59    set_and_get(5, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, 1);
60    set_and_get(6, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, 0);
61    set_and_get(7, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, -1);
62    $tmp = array();
63    set_and_get(8, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, $tmp);
64
65    set_and_get(9, $db, PPDO::MYSQL_ATTR_INIT_COMMAND, '');
66    set_and_get(10, $db, PPDO::MYSQL_ATTR_INIT_COMMAND, 'SOME SQL');
67    set_and_get(11, $db, PPDO::MYSQL_ATTR_INIT_COMMAND, -1);
68
69*/
70/*
71PDO::MYSQL_ATTR_READ_DEFAULT_FILE (integer)
72
73    Read options from the named option file instead of from my.cnf.
74PDO::MYSQL_ATTR_READ_DEFAULT_GROUP (integer)
75
76    Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE.
77PDO::MYSQL_ATTR_MAX_BUFFER_SIZE (integer)
78
79    Maximum buffer size. Defaults to 1 MiB.
80PDO::MYSQL_ATTR_DIRECT_QUERY (integer)
81
82    Perform direct queries, don't use prepared statements.
83*/
84/*
85TODO - read only
86PDO::ATTR_CONNECTION_STATUS
87PDO::ATTR_SERVER_INFO
88*/
89
90    print "done!";
91?>
92--CLEAN--
93<?php
94require __DIR__ . '/mysql_pdo_test.inc';
95MySQLPDOTest::dropTestTable();
96?>
97--EXPECT--
98done!
99