1--TEST--
2mysqli_change_user() - ROLLBACK
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8require_once('connect.inc');
9if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
10    die(sprintf("skip Cannot connect, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
11
12if (!have_innodb($link))
13    die(sprintf("skip Needs InnoDB support, [%d] %s", $link->errno, $link->error));
14?>
15--FILE--
16<?php
17    require_once('connect.inc');
18    require_once('table.inc');
19
20    if (!mysqli_query($link, 'ALTER TABLE test ENGINE=InnoDB'))
21        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
22
23    mysqli_autocommit($link, false);
24
25    if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))
26        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
27
28    if (!$row = mysqli_fetch_assoc($res))
29        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
30    mysqli_free_result($res);
31
32    $num = $row['_num'];
33    assert($num > 0);
34
35    if (!$res = mysqli_query($link, 'DELETE FROM test'))
36        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
37
38    if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))
39        printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
40
41    if (!$row = mysqli_fetch_assoc($res))
42        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43    mysqli_free_result($res);
44
45    if (0 != $row['_num'])
46        printf("[007] Rows should have been deleted in this transaction\n");
47
48    // DELETE should be rolled back
49    mysqli_change_user($link, $user, $passwd, $db);
50
51    if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS _num FROM test'))
52        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
53
54    if (!$row = mysqli_fetch_assoc($res))
55        printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
56
57    if ($row['_num'] != $num)
58        printf("[010] Expecting %d rows in the table test, found %d rows\n",
59            $num, $row['_num']);
60
61    mysqli_free_result($res);
62    mysqli_close($link);
63    print "done!";
64?>
65--CLEAN--
66<?php
67    require_once("clean_table.inc");
68?>
69--EXPECT--
70done!
71