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