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