1--TEST-- 2mysqli_stmt_insert_id() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 require('table.inc'); 14 15 $stmt = mysqli_stmt_init($link); 16 17 try { 18 mysqli_stmt_insert_id($stmt); 19 } catch (Error $exception) { 20 echo $exception->getMessage() . "\n"; 21 } 22 23 if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 1") || 24 !mysqli_stmt_execute($stmt)) { 25 printf("[004] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 26 } 27 28 if (0 !== ($tmp = mysqli_stmt_insert_id($stmt))) 29 printf("[005] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); 30 mysqli_stmt_close($stmt); 31 32 // no auto_increment column 33 $stmt = mysqli_stmt_init($link); 34 if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (100, 'a')") || 35 !mysqli_stmt_execute($stmt)) { 36 printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 37 } 38 39 if (0 !== ($tmp = mysqli_stmt_insert_id($stmt))) 40 printf("[007] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp); 41 42 if (mysqli_get_server_version($link) > 50000 && 43 (!mysqli_stmt_prepare($stmt, "ALTER TABLE test MODIFY id INT NOT NULL AUTO_INCREMENT") || 44 !mysqli_stmt_execute($stmt))) { 45 printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 46 } else if (mysqli_get_server_version($link) < 50000){ 47 mysqli_query($link, "ALTER TABLE test MODIFY id INT NOT NULL AUTO_INCREMENT"); 48 } 49 50 if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(label) VALUES ('a')") || 51 !mysqli_stmt_execute($stmt)) { 52 printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 53 } 54 if (0 === ($tmp = mysqli_stmt_insert_id($stmt))) 55 printf("[010] Expecting int/any non zero, got %s/%s\n", gettype($tmp), $tmp); 56 mysqli_stmt_close($stmt); 57 58 mysqli_close($link); 59 60 try { 61 mysqli_stmt_insert_id($stmt); 62 } catch (Error $exception) { 63 echo $exception->getMessage() . "\n"; 64 } 65 66 print "done!"; 67?> 68--CLEAN-- 69<?php 70 require_once("clean_table.inc"); 71?> 72--EXPECT-- 73mysqli_stmt object is not fully initialized 74mysqli_stmt object is already closed 75done! 76