1--TEST-- 2mysqli_stmt_get_warnings() - TODO 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7 8require_once("connect.inc"); 9 10if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { 11 die(sprintf("skip Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 12 $host, $user, $db, $port, $socket)); 13} 14 15if (!mysqli_query($link, "DROP TABLE IF EXISTS test") || 16 !mysqli_query($link, "CREATE TABLE test(id SMALLINT)")) 17 die(sprintf("skip [%d] %s\n", $link->errno, $link->error)); 18 19if (!@mysqli_query($link, "SET sql_mode=''") || !@mysqli_query($link, "INSERT INTO test(id) VALUES (100001)")) 20 die("skip Strict sql mode seems to be active. We won't get a warning to check for."); 21 22mysqli_query($link, "DROP TABLE IF EXISTS test"); 23?> 24--FILE-- 25<?php 26 require_once("connect.inc"); 27 28 require('table.inc'); 29 30 if (!$stmt = mysqli_stmt_init($link)) 31 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 32 33 try { 34 mysqli_stmt_get_warnings($stmt); 35 } catch (Error $exception) { 36 echo $exception->getMessage() . "\n"; 37 } 38 39 if (!mysqli_stmt_prepare($stmt, "SET sql_mode=''") || !mysqli_stmt_execute($stmt)) 40 printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 41 42 if (!mysqli_stmt_prepare($stmt, "DROP TABLE IF EXISTS test") || !mysqli_stmt_execute($stmt)) 43 printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 44 45 if (false !== ($tmp = mysqli_stmt_get_warnings($stmt))) 46 printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 47 48 if (!mysqli_stmt_prepare($stmt, "CREATE TABLE test(id SMALLINT, label CHAR(1))") || !mysqli_stmt_execute($stmt)) 49 printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 50 51 if (false !== ($tmp = mysqli_stmt_get_warnings($stmt))) 52 printf("[009] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 53 54 if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (100000, 'a'), (100001, 'b')") || 55 !mysqli_stmt_execute($stmt)) 56 printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 57 58 if (!is_object($warning = mysqli_stmt_get_warnings($stmt))) 59 printf("[011] Expecting mysqli_warning object, got %s/%s\n", gettype($warning), $warning); 60 61 if ('mysqli_warning' !== get_class($warning)) 62 printf("[012] Expecting object of type mysqli_warning got type '%s'", get_class($warning)); 63 64 if (!method_exists($warning, 'next')) 65 printf("[013] Object mysqli_warning seems to lack method next()\n"); 66 67 $i = 0; 68 do { 69 70 if ('' == $warning->message) 71 printf("[014 - %d] Message should not be empty\n", $i); 72 73 if ('' == $warning->sqlstate) 74 printf("[015 - %d] SQL State should not be empty\n", $i); 75 76 if (0 == $warning->errno) 77 printf("[016 - %d] Error number should not be zero\n", $i); 78 79 $i++; 80 81 } while ($warning->next()); 82 83 if (2 != $i) 84 printf("[017] Expected 2 warnings, got %d warnings\n", $i); 85 86 mysqli_stmt_close($stmt); 87 88 try { 89 mysqli_stmt_get_warnings($stmt); 90 } catch (Error $exception) { 91 echo $exception->getMessage() . "\n"; 92 } 93 94 mysqli_close($link); 95 print "done!"; 96?> 97--CLEAN-- 98<?php 99 require_once("clean_table.inc"); 100?> 101--EXPECT-- 102mysqli_stmt object is not fully initialized 103mysqli_stmt object is already closed 104done! 105