1--TEST-- 2mysqli_stmt_get_result() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 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 require('table.inc'); 22 23 if (!$stmt = mysqli_stmt_init($link)) 24 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 25 26 // stmt object status test 27 try { 28 mysqli_stmt_fetch($stmt); 29 } catch (Error $exception) { 30 echo $exception->getMessage() . "\n"; 31 } 32 33 if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2")) 34 printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 35 36 // FIXME - different versions return different values ?! 37 if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp)) 38 printf("[006] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 39 40 if (!mysqli_stmt_execute($stmt)) 41 printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 42 43 if (!mysqli_stmt_store_result($stmt)) 44 printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 45 46 if (is_object($tmp = mysqli_stmt_store_result($stmt))) 47 printf("[009] non-object, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 48 49 mysqli_stmt_close($stmt); 50 51 if (!$stmt = mysqli_stmt_init($link)) 52 printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 53 54 // stmt object status test 55 try { 56 mysqli_stmt_fetch($stmt); 57 } catch (Error $exception) { 58 echo $exception->getMessage() . "\n"; 59 } 60 61 if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test ORDER BY id LIMIT 2")) 62 printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 63 64 // FIXME - different versions return different values ?! 65 if ((NULL !== ($tmp = mysqli_stmt_get_result($stmt))) && (false !== $tmp)) 66 printf("[013] Expecting NULL or boolean/false, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 67 68 if (!mysqli_stmt_execute($stmt)) 69 printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 70 71 if (!is_object($tmp = mysqli_stmt_get_result($stmt))) 72 printf("[016] NULL, got %s/%s\n", gettype($tmp), var_export($tmp, 1)); 73 74 mysqli_free_result($tmp); 75 mysqli_stmt_close($stmt); 76 77 if (!$stmt = mysqli_stmt_init($link)) 78 printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 79 80 // stmt object status test 81 try { 82 mysqli_stmt_get_result($stmt); 83 } catch (Error $exception) { 84 echo $exception->getMessage() . "\n"; 85 } 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 try { 170 mysqli_stmt_fetch($stmt); 171 } catch (Error $exception) { 172 echo $exception->getMessage(), "\n"; 173 } 174 175 mysqli_close($link); 176 177 print "done!"; 178?> 179--CLEAN-- 180<?php 181 require_once("clean_table.inc"); 182?> 183--EXPECTF-- 184mysqli_stmt object is not fully initialized 185mysqli_stmt object is not fully initialized 186mysqli_stmt object is not fully initialized 187array(2) { 188 ["id"]=> 189 int(1) 190 ["label"]=> 191 string(1) "a" 192} 193array(2) { 194 ["id"]=> 195 int(2) 196 ["label"]=> 197 string(1) "b" 198} 199[040] [2014] [Commands out of sync; you can't run this command now] 200[041] [0] [] 201array(2) { 202 ["id"]=> 203 int(1) 204 ["label"]=> 205 %s(1) "a" 206} 207array(2) { 208 ["id"]=> 209 int(2) 210 ["label"]=> 211 %s(1) "b" 212} 213mysqli_stmt object is already closed 214done! 215