1--TEST--
2Checking last_insert_id after different operations
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10require_once("connect.inc");
11
12if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
13    printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
14                        $host, $user, $db, $port, $socket);
15
16$link->query("DROP TABLE IF EXISTS test_insert_id_var");
17$link->query("CREATE TABLE test_insert_id_var (id INT auto_increment, PRIMARY KEY (id))");
18$link->query("INSERT INTO test_insert_id_var VALUES (null)");
19$i = $link->insert_id;
20
21if (!$i) {
22    printf("[001] Got no valid insert id: %s", var_export($i, true));
23    die();
24}
25
26
27$link->options(MYSQLI_OPT_LOCAL_INFILE, false);
28if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
29    printf("[002] mysqli_option changes insert_id: %s", var_export($link->insert_id, true));
30    die();
31}
32
33/*
34$link->dump_debug_info();
35if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
36    printf("[003] mysqli_debug_info changes insert_id: %s", var_export($link->insert_id, true));
37    die();
38}
39*/
40
41$link->stat();
42if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
43    printf("[004] mysqli_stat changes insert_id: %s", var_export($link->insert_id, true));
44    die();
45}
46
47/*$link->kill($link->thread_id);
48if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
49    printf("[005] mysqli_kill changes insert_id: %s", var_export($link->insert_id, true));
50    die();
51}*/
52
53$link->ping();
54if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
55    printf("[006] mysqli_ping changes insert_id: %s", var_export($link->insert_id, true));
56    die();
57}
58
59/*
60mysqlnd resets the IDE to 0
61libmysql doesn't
62
63$link->change_user ($user, $passwd, $db);
64if (0 != $link->insert_id || 0 != mysqli_insert_id($link)) {
65    printf("[007] mysqli_change_user changes insert_id: %s", var_export($link->insert_id, true));
66    die();
67}
68*/
69
70$stmt = $link->prepare("SELECT 1");
71if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
72    printf("[008a] mysqli_prepare changes insert_id: %s", var_export($link->insert_id, true));
73    die();
74}
75echo mysqli_error($link);
76if (0 != $stmt->insert_id || 0 != mysqli_stmt_insert_id($stmt)) {
77    printf("[008b] mysqli_stmt doesn't initialise insert_id: %s", var_export($stmt->insert_id, true));
78    die();
79}
80
81unset($stmt);
82if ($i != $link->insert_id || $i != mysqli_insert_id($link)) {
83    printf("[009] stmt free changes insert_id: %s", var_export($link->insert_id, true));
84    die();
85}
86
87$link->query("DROP TABLE IF EXISTS test_insert_id_var");
88
89echo "DONE";
90?>
91--CLEAN--
92<?php
93require_once("connect.inc");
94if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
95   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
96
97if (!mysqli_query($link, "DROP TABLE IF EXISTS test_insert_id_var"))
98	printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
99
100mysqli_close($link);
101?>
102--EXPECT--
103DONE
104