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