mysqli_query_iterators.phpt 2.9 KB

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