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