1--TEST--
2MySQL PDO class inTransaction
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9?>
10--FILE--
11<?php
12require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
13
14const BEGIN = ['BEGIN', 'START TRANSACTION'];
15const END = ['COMMIT', 'ROLLBACK'];
16
17$db = MySQLPDOTest::factory();
18// $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); // mysql does not support
19foreach (BEGIN as $begin) {
20    foreach (END as $end) {
21        foreach (['exec', 'query', 'execute'] as $w) {
22            foreach ([$begin, $end] as $command) {
23                switch ($w) {
24                    case 'exec':
25                        $db->exec($command);
26                        break;
27                    case'query':
28                        $db->query($command)->execute();
29                        break;
30                    case 'execute':
31                        /* EMULATE_PREPARES = QUERY */
32                        $db->prepare($command)->execute();
33                        break;
34                    default:
35                        assert(0);
36                }
37                var_dump($db->inTransaction());
38            }
39        }
40    }
41}
42echo "\n";
43
44// Mixing PDO transaction API and explicit queries.
45foreach (END as $end) {
46    $db->beginTransaction();
47    var_dump($db->inTransaction());
48    $db->exec($end);
49    var_dump($db->inTransaction());
50}
51
52$db->exec('START TRANSACTION');
53var_dump($db->inTransaction());
54$db->rollBack();
55var_dump($db->inTransaction());
56$db->exec('START TRANSACTION');
57var_dump($db->inTransaction());
58$db->commit();
59var_dump($db->inTransaction());
60echo "\n";
61
62// DDL query causes an implicit commit.
63$db->beginTransaction();
64var_dump($db->inTransaction());
65$db->exec('DROP TABLE IF EXISTS test');
66var_dump($db->inTransaction());
67
68// We should be able to start a new transaction after the implicit commit.
69$db->beginTransaction();
70var_dump($db->inTransaction());
71$db->commit();
72var_dump($db->inTransaction());
73
74?>
75--EXPECT--
76bool(true)
77bool(false)
78bool(true)
79bool(false)
80bool(true)
81bool(false)
82bool(true)
83bool(false)
84bool(true)
85bool(false)
86bool(true)
87bool(false)
88bool(true)
89bool(false)
90bool(true)
91bool(false)
92bool(true)
93bool(false)
94bool(true)
95bool(false)
96bool(true)
97bool(false)
98bool(true)
99bool(false)
100
101bool(true)
102bool(false)
103bool(true)
104bool(false)
105bool(true)
106bool(false)
107bool(true)
108bool(false)
109
110bool(true)
111bool(false)
112bool(true)
113bool(false)
114