1--TEST-- 2mysqli_stmt_execute() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once('skipifconnectfailure.inc'); 8if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { 9 die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error())); 10} 11if (mysqli_get_server_version($link) <= 40100) { 12 die(sprintf('skip Needs MySQL 4.1+, found version %d.', mysqli_get_server_version($link))); 13} 14?> 15--FILE-- 16<?php 17 require_once("connect.inc"); 18 19 require('table.inc'); 20 21 if (!$stmt = mysqli_stmt_init($link)) 22 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 23 24 // stmt object status test 25 try { 26 mysqli_stmt_execute($stmt); 27 } catch (Error $exception) { 28 echo $exception->getMessage() . "\n"; 29 } 30 31 if (mysqli_stmt_prepare($stmt, "SELECT i_do_not_exist_believe_me FROM test ORDER BY id")) 32 printf("[005] Statement should have failed!\n"); 33 34 // stmt object status test 35 try { 36 mysqli_stmt_execute($stmt); 37 } catch (Error $exception) { 38 echo $exception->getMessage() . "\n"; 39 } 40 41 if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT 1")) 42 printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 43 44 if (true !== ($tmp = mysqli_stmt_execute($stmt))) 45 printf("[008] Expecting boolean/true, got %s/%s. [%d] %s\n", 46 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 47 48 if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)")) 49 printf("[009] [%d] %s\n", mysqli_stmt_execute($stmt), mysqli_stmt_execute($stmt)); 50 51 // no input variables bound 52 if (false !== ($tmp = mysqli_stmt_execute($stmt))) 53 printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 54 55 $id = 100; 56 $label = "z"; 57 if (!mysqli_stmt_bind_param($stmt, "is", $id, $label)) 58 printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 59 60 if (true !== ($tmp = mysqli_stmt_execute($stmt))) 61 printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 62 63 // calling reset between executions 64 mysqli_stmt_close($stmt); 65 if (!$stmt = mysqli_stmt_init($link)) 66 printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 67 68 if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT ?")) 69 printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 70 71 $limit = 1; 72 if (!mysqli_stmt_bind_param($stmt, "i", $limit)) 73 printf("[015] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 74 75 if (true !== ($tmp = mysqli_stmt_execute($stmt))) 76 printf("[016] Expecting boolean/true, got %s/%s. [%d] %s\n", 77 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 78 79 $id = null; 80 if (!mysqli_stmt_bind_result($stmt, $id) || !mysqli_stmt_fetch($stmt)) 81 printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 82 83 if ($id !== 1) 84 printf("[018] Expecting int/1 got %s/%s\n", gettype($id), $id); 85 86 if (true !== ($tmp = mysqli_stmt_reset($stmt))) 87 printf("[019] Expecting boolean/true, got %s/%s. [%d] %s\n", 88 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 89 90 if (true !== ($tmp = mysqli_stmt_execute($stmt))) 91 printf("[020] Expecting boolean/true after reset to prepare status, got %s/%s. [%d] %s\n", 92 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 93 94 $id = null; 95 if (!mysqli_stmt_fetch($stmt)) 96 printf("[021] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 97 98 if ($id !== 1) 99 printf("[022] Expecting int/1 got %s/%s\n", gettype($id), $id); 100 101 mysqli_stmt_close($stmt); 102 if (!$stmt = mysqli_stmt_init($link)) 103 printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 104 105 if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT 1")) 106 printf("[024] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 107 108 if (true !== ($tmp = mysqli_stmt_execute($stmt))) 109 printf("[025] Expecting boolean/true, got %s/%s. [%d] %s\n", 110 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 111 112 if (true !== ($tmp = mysqli_stmt_reset($stmt))) 113 printf("[026] Expecting boolean/true, got %s/%s. [%d] %s\n", 114 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 115 116 var_dump(mysqli_stmt_execute($stmt)); 117 var_dump(mysqli_stmt_fetch($stmt)); 118 119 mysqli_kill($link, mysqli_thread_id($link)); 120 121 if (false !== ($tmp = mysqli_stmt_execute($stmt))) 122 printf("[027] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 123 124 mysqli_stmt_close($stmt); 125 126 try { 127 mysqli_stmt_execute($stmt); 128 } catch (Error $exception) { 129 echo $exception->getMessage() . "\n"; 130 } 131 132 mysqli_close($link); 133 print "done!"; 134?> 135--CLEAN-- 136<?php 137 require_once("clean_table.inc"); 138?> 139--EXPECT-- 140mysqli_stmt object is not fully initialized 141mysqli_stmt object is not fully initialized 142bool(true) 143bool(true) 144[027] Expecting boolean/false, got boolean/1 145mysqli_stmt object is already closed 146done! 147