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