1--TEST-- 2mysqli_stmt_get_result() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8 9if (!function_exists('mysqli_stmt_get_result')) 10 die('skip mysqli_stmt_get_result not available'); 11?> 12--FILE-- 13<?php 14 /* 15 NOTE: no datatype tests here! This is done by 16 mysqli_stmt_bind_result.phpt already. Restrict 17 this test case to the basics. 18 */ 19 require_once("connect.inc"); 20 21 $tmp = NULL; 22 $link = NULL; 23 24 if (!is_null($tmp = @mysqli_stmt_get_result())) 25 printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 26 27 if (!is_null($tmp = @mysqli_stmt_get_result($link))) 28 printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 29 30 require('table.inc'); 31 32 if (!$stmt = mysqli_stmt_init($link)) 33 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 34 35 // stmt object status test 36 if (false !== ($tmp = mysqli_stmt_fetch($stmt))) 37 printf("[004] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 38 39 if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2")) 40 printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 41 42 // FIXME - different versions return different values ?! 43 if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp)) 44 printf("[006] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 45 46 if (!mysqli_stmt_execute($stmt)) 47 printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 48 49 if (!mysqli_stmt_store_result($stmt)) 50 printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 51 52 if (is_object($tmp = mysqli_stmt_store_result($stmt))) 53 printf("[009] non-object, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 54 55 mysqli_stmt_close($stmt); 56 57 if (!$stmt = mysqli_stmt_init($link)) 58 printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 59 60 // stmt object status test 61 if (false !== ($tmp = mysqli_stmt_fetch($stmt))) 62 printf("[011] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 63 64 if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2")) 65 printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 66 67 // FIXME - different versions return different values ?! 68 if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp)) 69 printf("[013] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 70 71 if (!mysqli_stmt_execute($stmt)) 72 printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 73 74 if (!is_object($tmp = mysqli_stmt_get_result($stmt))) 75 printf("[016] NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 76 77 mysqli_free_result($tmp); 78 mysqli_stmt_close($stmt); 79 80 if (!$stmt = mysqli_stmt_init($link)) 81 printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 82 83 // stmt object status test 84 if (false !== ($tmp = mysqli_stmt_get_result($stmt))) 85 printf("[018] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 86 87 if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2")) 88 printf("[019] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 89 90 if (false !== ($tmp = mysqli_stmt_get_result($stmt))) 91 printf("[020] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 92 93 if (!mysqli_stmt_execute($stmt)) 94 printf("[023] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 95 96 if (!is_object($tmp = mysqli_stmt_get_result($stmt))) 97 printf("[024] Expecting object, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 98 99 if (false !== ($tmp = mysqli_stmt_fetch($stmt))) 100 printf("[025] false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 101 102 if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label))) { 103 printf("[026] [%d] [%s]\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 104 printf("[027] [%d] [%s]\n", mysqli_errno($link), mysqli_error($link)); 105 printf("[028] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 106 } 107 108 if (false !== ($tmp = mysqli_stmt_fetch($stmt))) 109 printf("[029] false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 110 111 mysqli_stmt_close($stmt); 112 113 // get_result can be used in PS cursor mode 114 if (!$stmt = mysqli_stmt_init($link)) 115 printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 116 117 if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2")) 118 printf("[031] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 119 120 if (!mysqli_stmt_attr_set($stmt, MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_READ_ONLY)) 121 printf("[032] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 122 123 if (!mysqli_stmt_execute($stmt)) 124 printf("[033] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 125 126 $result = mysqli_stmt_get_result($stmt); 127 while ($row = mysqli_fetch_assoc($result)) { 128 var_dump($row); 129 } 130 131 if (!$stmt = mysqli_stmt_init($link)) 132 printf("[034] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 133 134 if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2")) 135 printf("[035] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 136 137 if (!mysqli_stmt_execute($stmt)) 138 printf("[036] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 139 140 $id = NULL; 141 $label = NULL; 142 if (true !== ($tmp = mysqli_stmt_bind_result($stmt, $id, $label))) 143 printf("[037] Expecting boolean/true, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 144 145 if (!is_object($tmp = $result = mysqli_stmt_get_result($stmt))) 146 printf("[038] Expecting array, got %s/%s, [%d] %s\n", 147 gettype($tmp), var_export($tmp, 1), 148 mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 149 150 if (false !== ($tmp = mysqli_stmt_fetch($stmt))) 151 printf("[039] Expecting boolean/false, got %s/%s, [%d] %s\n", 152 gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 153 154 printf("[040] [%d] [%s]\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 155 printf("[041] [%d] [%s]\n", mysqli_errno($link), mysqli_error($link)); 156 while ($row = mysqli_fetch_assoc($result)) { 157 var_dump($row); 158 } 159 mysqli_free_result($result); 160 161 if (!mysqli_kill($link, mysqli_thread_id($link))) 162 printf("[042] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 163 164 if (false !== ($tmp = mysqli_stmt_get_result($stmt))) 165 printf("[043] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 166 167 mysqli_stmt_close($stmt); 168 169 if (false !== ($tmp = mysqli_stmt_fetch($stmt))) 170 printf("[044] Expecting false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 171 172 mysqli_close($link); 173 174 print "done!"; 175?> 176--CLEAN-- 177<?php 178 require_once("clean_table.inc"); 179?> 180--EXPECTF-- 181Warning: mysqli_stmt_fetch(): invalid object or resource mysqli_stmt 182 in %s on line %d 183 184Warning: mysqli_stmt_fetch(): invalid object or resource mysqli_stmt 185 in %s on line %d 186 187Warning: mysqli_stmt_get_result(): invalid object or resource mysqli_stmt 188 in %s on line %d 189array(2) { 190 ["id"]=> 191 int(1) 192 ["label"]=> 193 string(1) "a" 194} 195array(2) { 196 ["id"]=> 197 int(2) 198 ["label"]=> 199 string(1) "b" 200} 201[040] [2014] [Commands out of sync; you can't run this command now] 202[041] [0] [] 203array(2) { 204 ["id"]=> 205 int(1) 206 ["label"]=> 207 %s(1) "a" 208} 209array(2) { 210 ["id"]=> 211 int(2) 212 ["label"]=> 213 %s(1) "b" 214} 215 216Warning: mysqli_stmt_fetch(): Couldn't fetch mysqli_stmt in %s on line %d 217done! 218