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