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