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