1--TEST-- 2mysqli iterators 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 $tmp = NULL; 14 $link = NULL; 15 16 require('table.inc'); 17 18 echo "--- Testing default ---\n"; 19 if (!is_object($res = mysqli_query($link, "SELECT id FROM test ORDER BY id"))) 20 printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 21 else { 22 foreach ($res as $row) { 23 var_dump($row); 24 } 25 echo "======\n"; 26 27 foreach ($res as $row) { 28 var_dump($row); 29 } 30 mysqli_free_result($res); 31 try { 32 foreach ($res as $row) { 33 $row; 34 } 35 } catch (Error $exception) { 36 echo $exception->getMessage() . "\n"; 37 } 38 } 39 echo "--- Testing USE_RESULT ---\n"; 40 if (!is_object($res = mysqli_query($link, "SELECT id FROM test ORDER BY id", MYSQLI_USE_RESULT))) 41 printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 42 else { 43 foreach ($res as $row) { 44 var_dump($row); 45 } 46 echo "======\n"; 47 foreach ($res as $row) { 48 var_dump($row); 49 } 50 mysqli_free_result($res); 51 } 52 53 echo "--- Testing STORE_RESULT ---\n"; 54 if (!is_object($res = mysqli_query($link, "SELECT id FROM test ORDER BY id", MYSQLI_STORE_RESULT))) 55 printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 56 else { 57 foreach ($res as $row) { 58 var_dump($row); 59 } 60 echo "======\n"; 61 foreach ($res as $row) { 62 var_dump($row); 63 } 64 mysqli_free_result($res); 65 } 66 67 mysqli_close($link); 68 69 print "done!"; 70?> 71--CLEAN-- 72<?php 73 require_once("clean_table.inc"); 74?> 75--EXPECTF-- 76--- Testing default --- 77array(1) { 78 ["id"]=> 79 string(1) "1" 80} 81array(1) { 82 ["id"]=> 83 string(1) "2" 84} 85array(1) { 86 ["id"]=> 87 string(1) "3" 88} 89array(1) { 90 ["id"]=> 91 string(1) "4" 92} 93array(1) { 94 ["id"]=> 95 string(1) "5" 96} 97array(1) { 98 ["id"]=> 99 string(1) "6" 100} 101====== 102array(1) { 103 ["id"]=> 104 string(1) "1" 105} 106array(1) { 107 ["id"]=> 108 string(1) "2" 109} 110array(1) { 111 ["id"]=> 112 string(1) "3" 113} 114array(1) { 115 ["id"]=> 116 string(1) "4" 117} 118array(1) { 119 ["id"]=> 120 string(1) "5" 121} 122array(1) { 123 ["id"]=> 124 string(1) "6" 125} 126mysqli_result object is already closed 127--- Testing USE_RESULT --- 128array(1) { 129 ["id"]=> 130 string(1) "1" 131} 132array(1) { 133 ["id"]=> 134 string(1) "2" 135} 136array(1) { 137 ["id"]=> 138 string(1) "3" 139} 140array(1) { 141 ["id"]=> 142 string(1) "4" 143} 144array(1) { 145 ["id"]=> 146 string(1) "5" 147} 148array(1) { 149 ["id"]=> 150 string(1) "6" 151} 152====== 153 154Warning: main(): Data fetched with MYSQLI_USE_RESULT can be iterated only once in %s on line %d 155--- Testing STORE_RESULT --- 156array(1) { 157 ["id"]=> 158 string(1) "1" 159} 160array(1) { 161 ["id"]=> 162 string(1) "2" 163} 164array(1) { 165 ["id"]=> 166 string(1) "3" 167} 168array(1) { 169 ["id"]=> 170 string(1) "4" 171} 172array(1) { 173 ["id"]=> 174 string(1) "5" 175} 176array(1) { 177 ["id"]=> 178 string(1) "6" 179} 180====== 181array(1) { 182 ["id"]=> 183 string(1) "1" 184} 185array(1) { 186 ["id"]=> 187 string(1) "2" 188} 189array(1) { 190 ["id"]=> 191 string(1) "3" 192} 193array(1) { 194 ["id"]=> 195 string(1) "4" 196} 197array(1) { 198 ["id"]=> 199 string(1) "5" 200} 201array(1) { 202 ["id"]=> 203 string(1) "6" 204} 205done! 206