1--TEST--
2MySQL PDO->exec(), SELECT
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12    function exec_and_count($offset, &$db, $sql, $exp) {
13
14        try {
15
16            $ret = $db->exec($sql);
17            if ($ret !== $exp) {
18                printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n",
19                    $offset, $exp, gettype($exp), $ret, gettype($ret), $sql,
20                    $db->errorCode(), implode(' ', $db->errorInfo()));
21                return false;
22            }
23
24        } catch (PDOException $e) {
25            printf("[%03d] '%s' has failed, [%s] %s\n",
26                $offset, $sql, $db->errorCode(), implode(' ', $db->errorInfo()));
27            return false;
28        }
29
30        return true;
31    }
32
33    require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
34    $db = MySQLPDOTest::factory();
35    MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
36
37    /* affected rows related */
38    try {
39
40        exec_and_count(2, $db, 'DROP TABLE IF EXISTS test', 0);
41        exec_and_count(3, $db, sprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s', PDO_MYSQL_TEST_ENGINE), 0);
42        exec_and_count(4, $db, "INSERT INTO test(id, col1) VALUES (1, 'a')", 1);
43        // question is: will the result set be cleaned up, will it be possible to run more queries on the line?
44        // buffered or unbuffered does not matter!
45        $db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
46        exec_and_count(5, $db, 'SELECT id FROM test', 0);
47        exec_and_count(6, $db, "INSERT INTO test(id, col1) VALUES (2, 'b')", 1);
48
49    } catch (PDOException $e) {
50        printf("[001] %s, [%s] %s\n",
51            $e->getMessage(),
52            $db->errorCode(), implode(' ', $db->errorInfo()));
53    }
54
55    print "done!";
56?>
57--CLEAN--
58<?php
59require __DIR__ . '/mysql_pdo_test.inc';
60$db = MySQLPDOTest::factory();
61@$db->exec('DROP TABLE IF EXISTS test');
62?>
63--EXPECTF--
64Warning: PDO::exec(): SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. in %s on line %d
65[006] Expecting '1'/integer got ''/boolean when running 'INSERT INTO test(id, col1) VALUES (2, 'b')', [HY000] HY000 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.
66done!
67