1--TEST--
2mysqli iterators
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
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		foreach ($res as $row) {
27			var_dump($row);
28		}
29		mysqli_free_result($res);
30		foreach ($res as $row) {
31			var_dump($row);
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}
121
122Warning: main(): Couldn't fetch mysqli_result in %s on line %d
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: main(): 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!