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