1--TEST--
2mysqli_rollback()
3--SKIPIF--
4<?php  ?>
5<?php  ?>
6<?PHP
7	require_once('skipif.inc');
8	require_once('skipifemb.inc');
9	require_once('skipifconnectfailure.inc');
10
11	require_once('connect.inc');
12	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
13		die(sprintf("Cannot connect, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
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_rollback()))
26		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
27
28	if (!is_null($tmp = @mysqli_rollback($link)))
29		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
30
31	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
32		printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
33			$host, $user, $db, $port, $socket);
34
35	if (!is_null($tmp = @mysqli_rollback($link, 'foo')))
36		printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
37
38	if (true !== ($tmp = mysqli_autocommit($link, false)))
39		printf("[005] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
40
41	if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
42		printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43
44	if (!mysqli_query($link, 'CREATE TABLE test(id INT) ENGINE = InnoDB'))
45		printf("[007] Cannot create test table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
46
47	if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1)'))
48		printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
49
50	$tmp = mysqli_rollback($link);
51	if ($tmp !== true)
52		printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
53
54	if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS num FROM test'))
55		printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
56	$tmp = mysqli_fetch_assoc($res);
57	if (0 != $tmp['num'])
58		printf("[12] Expecting 0 rows in table test, found %d rows\n", $tmp['num']);
59	mysqli_free_result($res);
60
61	if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
62		printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
63
64	mysqli_close($link);
65
66	if (!is_null($tmp = mysqli_rollback($link)))
67		printf("[014] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
68
69	print "done!\n";
70?>
71--CLEAN--
72<?php
73	require_once("clean_table.inc");
74?>
75--EXPECTF--
76Warning: mysqli_rollback(): Couldn't fetch mysqli in %s on line %d
77done!