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