1--TEST--
2mysqli_change_user() - LAST_INSERT_ID() - http://bugs.mysql.com/bug.php?id=45184?
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11    require_once 'connect.inc';
12
13    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
14        printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
15
16    if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
17        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
18
19    if (!mysqli_query($link, 'CREATE TABLE test(id INT AUTO_INCREMENT PRIMARY KEY, label CHAR(10))'))
20        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
21
22    if (!mysqli_query($link, "INSERT INTO test(id, label) VALUES (100, 'z')"))
23        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
24
25    if (($insert_id = mysqli_insert_id($link)) !== 100)
26        printf("[005] Expecting 100, got %d, [%d] %s\n",
27            $insert_id,
28            mysqli_errno($link), mysqli_error($link));
29
30    // LAST_INSERT_ID should be reset
31    mysqli_change_user($link, $user, $passwd, $db);
32
33    if (($insert_id = mysqli_insert_id($link)) !== 0)
34            printf("[006] Expecting 0, got %d, [%d] %s\n",
35                $insert_id,
36                mysqli_errno($link), mysqli_error($link));
37
38    if (!$res = mysqli_query($link, 'SELECT LAST_INSERT_ID() as _insert_id'))
39        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
40
41    if (!$row = mysqli_fetch_assoc($res))
42        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43    mysqli_free_result($res);
44
45    if ($row['_insert_id'] != $insert_id)
46        printf("LAST_INSERT_ID() [%d] and mysqli_insert_id [%d] differ!\n",
47            $row['_insert_id'], $insert_id);
48
49    if ($row['_insert_id'] != 0)
50        printf("Expecting 0 got %d\n", $row['_insert_id']);
51
52    mysqli_close($link);
53    print "done!";
54?>
55--CLEAN--
56<?php
57require_once "clean_table.inc";
58?>
59--EXPECT--
60done!
61