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