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