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