1--TEST--
2mysqli_change_user() - 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 'table.inc';
17
18    if (!mysqli_query($link, 'ALTER TABLE test ENGINE=InnoDB'))
19        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
20
21    mysqli_autocommit($link, false);
22
23    if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))
24        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
25
26    if (!$row = mysqli_fetch_assoc($res))
27        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
28    mysqli_free_result($res);
29
30    $num = $row['_num'];
31    assert($num > 0);
32
33    if (!$res = mysqli_query($link, 'DELETE FROM test'))
34        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
35
36    if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))
37        printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
38
39    if (!$row = mysqli_fetch_assoc($res))
40        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
41    mysqli_free_result($res);
42
43    if (0 != $row['_num'])
44        printf("[007] Rows should have been deleted in this transaction\n");
45
46    // DELETE should be rolled back
47    mysqli_change_user($link, $user, $passwd, $db);
48
49    if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))
50        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
51
52    if (!$row = mysqli_fetch_assoc($res))
53        printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
54
55    if ($row['_num'] != $num)
56        printf("[010] Expecting %d rows in the table test, found %d rows\n",
57            $num, $row['_num']);
58
59    mysqli_free_result($res);
60    mysqli_close($link);
61    print "done!";
62?>
63--CLEAN--
64<?php
65require_once "clean_table.inc";
66?>
67--EXPECT--
68done!
69