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