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