1--TEST--
2mysqli_more_results()
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	$strict_on = false;
14	if (defined('E_STRICT')) {
15		error_reporting(((int)ini_get('error_reporting')) | E_STRICT );
16		$strict_on = true;
17	}
18
19	$tmp    = NULL;
20	$link   = NULL;
21
22	if (!is_null($tmp = @mysqli_more_results()))
23		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
24
25	if (!is_null($tmp = @mysqli_more_results($link)))
26		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
27
28	require('table.inc');
29
30	print "[004]\n";
31	var_dump(mysqli_more_results($link));
32
33	if (!mysqli_multi_query($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3"))
34		printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
35	print "[006]\n";
36	$i = 1;
37
38	if ($strict_on)
39		ob_start();
40
41	if (mysqli_get_server_version($link) > 41000 && !($ret = mysqli_more_results($link)))
42		printf("[007] Expecting boolean/true, got %s/%s\n", gettype($ret), $ret);
43	do {
44		$res = mysqli_store_result($link);
45		mysqli_free_result($res);
46		if (mysqli_more_results($link))
47			printf("%d\n", $i++);
48	} while (mysqli_next_result($link));
49
50	if ($strict_on) {
51		$tmp = ob_get_contents();
52		ob_end_clean();
53		if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
54			printf("[008] Strict Standards warning missing\n");
55		} else {
56			$tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
57		}
58			print trim($tmp) . "\n";
59	}
60
61	if (!mysqli_multi_query($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3"))
62		printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
63	print "[010]\n";
64	$i = 1;
65	if (mysqli_get_server_version($link) > 41000 && !($ret = mysqli_more_results($link)))
66		printf("[011] Expecting boolean/true, got %s/%s\n", gettype($ret), $ret);
67
68	if ($strict_on)
69		ob_start();
70	do {
71		$res = mysqli_use_result($link);
72		// NOTE: if you use mysqli_use_result() with mysqli_more_results() or any other info function,
73		// you must fetch all rows before you can loop to the next result set!
74		// See also the MySQL Reference Manual: mysql_use_result()
75		while ($row = mysqli_fetch_array($res))
76			;
77		mysqli_free_result($res);
78		if (mysqli_more_results($link))
79			printf("%d\n", $i++);
80	} while (mysqli_next_result($link));
81
82	if ($strict_on) {
83		$tmp = ob_get_contents();
84		ob_end_clean();
85		if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
86			printf("[008] Strict Standards warning missing\n");
87		} else {
88			$tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
89		}
90		print trim($tmp) . "\n";
91	}
92	mysqli_close($link);
93
94	var_dump(mysqli_more_results($link));
95
96	print "done!";
97?>
98--CLEAN--
99<?php
100	require_once("clean_table.inc");
101?>
102--EXPECTF--
103[004]
104bool(false)
105[006]
1061
1072
108[010]
1091
1102
111
112Warning: mysqli_more_results(): Couldn't fetch mysqli in %s on line %d
113NULL
114done!
115