1--TEST--
2mysqli->autocommit()
3--SKIPIF--
4<?php
5    require_once('skipif.inc');
6    require_once('skipifconnectfailure.inc');
7    require_once('connect.inc');
8
9    if (!$link = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
10        printf("skip Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
11            $host, $user, $db, $port, $socket);
12        exit(1);
13    }
14
15    if (!have_innodb($link))
16        die(sprintf("skip Needs InnoDB support, [%d] %s", $link->errno, $link->error));
17?>
18--FILE--
19<?php
20    require_once("connect.inc");
21
22    if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
23        printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
24            $host, $user, $db, $port, $socket);
25    }
26
27    if (!is_bool($tmp = $mysqli->autocommit(true)))
28        printf("[002] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp);
29
30    if (!$mysqli->query('SET AUTOCOMMIT = 0'))
31        printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);
32
33    if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit'))
34        printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
35
36    $tmp = $res->fetch_assoc();
37    $res->free_result();
38    if ($tmp['auto_commit'])
39        printf("[005] Cannot turn off autocommit\n");
40
41    if (true !== ($tmp = $mysqli->autocommit( true)))
42        printf("[006] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
43
44    if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit'))
45        printf("[007] [%d] %s\n", $mysqli->errno, $mysqli->error);
46    $tmp = $res->fetch_assoc();
47    $res->free_result();
48    if (!$tmp['auto_commit'])
49        printf("[008] Cannot turn on autocommit\n");
50
51    if (!$mysqli->query('DROP TABLE IF EXISTS test'))
52        printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error);
53
54    if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) {
55        printf("[010] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error);
56    }
57
58    if (!$mysqli->query('INSERT INTO test(id) VALUES (1)'))
59        printf("[011] [%d] %s\n", $mysqli->errno, $mysqli->error);
60
61    if (!$mysqli->query('ROLLBACK'))
62        printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error);
63
64    if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test'))
65        printf("[013] [%d] %s\n", $mysqli->errno, $mysqli->error);
66
67    if ((!$tmp = $res->fetch_assoc()) || (1 != $tmp['num']))
68        printf("[014] Expecting 1 row in table test, found %d rows. [%d] %s\n",
69            $tmp['num'], $mysqli->errno, $mysqli->error);
70
71    $res->free_result();
72
73    if (!$mysqli->query('DROP TABLE IF EXISTS test'))
74        printf("[015] [%d] %s\n", $mysqli->errno, $mysqli->error);
75
76    if (!$mysqli->query('SET AUTOCOMMIT = 1'))
77        printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error);
78
79    if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit'))
80        printf("[017] [%d] %s\n", $mysqli->errno, $mysqli->error);
81
82    $tmp = $res->fetch_assoc();
83    $res->free_result();
84    if (!$tmp['auto_commit'])
85        printf("[018] Cannot turn on autocommit\n");
86
87    if (true !== ($tmp = $mysqli->autocommit( false)))
88        printf("[019] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
89
90    if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) {
91        printf("[020] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error);
92    }
93
94    if (!$mysqli->query('INSERT INTO test(id) VALUES (1)'))
95        printf("[021] [%d] %s\n", $mysqli->errno, $mysqli->error);
96
97    if (!$mysqli->query('ROLLBACK'))
98        printf("[022] [%d] %s\n", $mysqli->errno, $mysqli->error);
99
100    if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test'))
101        printf("[023] [%d] %s\n", $mysqli->errno, $mysqli->error);
102    $tmp = $res->fetch_assoc();
103    if (0 != $tmp['num'])
104        printf("[24] Expecting 0 rows in table test, found %d rows\n", $tmp['num']);
105    $res->free_result();
106
107    if (!$mysqli->query('INSERT INTO test(id) VALUES (1)'))
108        printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error);
109
110    if (!$mysqli->query('COMMIT'))
111        printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error);
112
113    if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test'))
114        printf("[027] [%d] %s\n", $mysqli->errno, $mysqli->error);
115
116    if ((!$tmp = $res->fetch_assoc()) || (1 != $tmp['num']))
117        printf("[028] Expecting 1 row in table test, found %d rows. [%d] %s\n",
118            $tmp['num'], $mysqli->errno, $mysqli->error);
119    $res->free_result();
120
121    if (!$mysqli->query('DROP TABLE IF EXISTS test'))
122        printf("[029] [%d] %s\n", $mysqli->errno, $mysqli->error);
123
124    $mysqli->close();
125
126    try {
127        $mysqli->autocommit(false);
128    } catch (Error $exception) {
129        echo $exception->getMessage() . "\n";
130    }
131
132    print "done!";
133?>
134--CLEAN--
135<?php
136    require_once("clean_table.inc");
137?>
138--EXPECT--
139my_mysqli object is already closed
140done!
141