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