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