summaryrefslogtreecommitdiff
path: root/ext/mysqli/tests/mysqli_next_result.phpt
blob: c36920e1ecc85a7df3b85d823fa2cb2909ea1946 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
--TEST--
mysqli_next_result()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
	require_once("connect.inc");

	$strict_on = false;
	if (defined('E_STRICT')) {
		error_reporting(((int)ini_get('error_reporting')) | E_STRICT );
		$strict_on = true;
	}

	$tmp    = NULL;
	$link   = NULL;

	if (!is_null($tmp = @mysqli_next_result()))
		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);

	if (!is_null($tmp = @mysqli_next_result($link)))
		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);

	require('table.inc');

	if ($strict_on)
		ob_start();

	if (false !== ($tmp = mysqli_next_result($link)))
		printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);

	if ($strict_on) {
		$tmp = ob_get_contents();
		ob_end_clean();
		if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
			printf("[003a] Strict Standards warning missing\n");
		} else {
			$tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
		}
		print trim($tmp) . "\n";
		ob_start();
	}

	$res = mysqli_query($link, "SELECT 1 AS res");
	if (false !== ($tmp = mysqli_next_result($link)))
		printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);

	if ($strict_on) {
		$tmp = ob_get_contents();
		ob_end_clean();
		if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
			printf("[004a] Strict Standards warning missing\n");
		} else {
			$tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
		}
		print trim($tmp) . "\n";
	}

	mysqli_free_result($res);

	function func_test_mysqli_next_result($link, $query, $offset, $num_results, $strict_on) {

		if (!mysqli_multi_query($link, $query))
			printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));

		$i = 0;
		if ($strict_on)
			ob_start();

		do {
			if ($res = mysqli_store_result($link)) {
				mysqli_free_result($res);
				$i++;
			}
		} while (true === mysqli_next_result($link));

		if ($strict_on) {
			$tmp = ob_get_contents();
			ob_end_clean();
			if (!preg_match('@Strict Standards: mysqli_next_result\(\): There is no next result set@ismU', $tmp)) {
				printf("[%03d] Strict Standards warning missing\n", $offset + 1);
			} else {
				$tmp = trim(preg_replace('@Strict Standards: mysqli_next_result\(\).*on line \d+@ism', '', $tmp));
			}
			print trim($tmp) . "\n";
		}

		if ($i !== $num_results) {
			printf("[%03d] Expecting %d result(s), got %d result(s)\n", $offset + 2, $num_results, $i);
		}

		if (mysqli_more_results($link))
			printf("[%03d] mysqli_more_results() indicates more results than expected\n", $offset + 3);

		if (!($res = mysqli_query($link, "SELECT 1 AS b"))) {
			printf("[%03d] [%d] %s\n", $offset + 4, mysqli_errno($link), mysqli_error($link));
		} else {
			mysqli_free_result($res);
		}

	}

	func_test_mysqli_next_result($link, "SELECT 1 AS a; SELECT 1 AS a, 2 AS b; SELECT id FROM test ORDER BY id LIMIT 3", 5, 3, $strict_on);
	func_test_mysqli_next_result($link, "SELECT 1 AS a; INSERT INTO test(id, label) VALUES (100, 'y'); SELECT 1 AS a, 2 AS b", 8, 2, $strict_on);
	func_test_mysqli_next_result($link, "DELETE FROM test WHERE id >= 100; SELECT 1 AS a; ", 11, 1, $strict_on);

	mysqli_close($link);

	var_dump(mysqli_next_result($link));

	print "done!";
?>
--CLEAN--
<?php
	require_once("clean_table.inc");
?>
--EXPECTF--
Warning: mysqli_next_result(): Couldn't fetch mysqli in %s on line %d
NULL
done!