1--TEST--
2mysqli_next_result()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once("connect.inc");
12
13    require('table.inc');
14
15    if (false !== ($tmp = mysqli_next_result($link)))
16        printf("[003] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
17
18    $res = mysqli_query($link, "SELECT 1 AS res");
19    if (false !== ($tmp = mysqli_next_result($link)))
20        printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
21
22    mysqli_free_result($res);
23
24    function func_test_mysqli_next_result($link, $query, $offset, $num_results) {
25
26        if (!mysqli_multi_query($link, $query))
27            printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
28
29        $i = 0;
30        do {
31            if ($res = mysqli_store_result($link)) {
32                mysqli_free_result($res);
33                $i++;
34            }
35        } while (true === mysqli_next_result($link));
36
37        if ($i !== $num_results) {
38            printf("[%03d] Expecting %d result(s), got %d result(s)\n", $offset + 2, $num_results, $i);
39        }
40
41        if (mysqli_more_results($link))
42            printf("[%03d] mysqli_more_results() indicates more results than expected\n", $offset + 3);
43
44        if (!($res = mysqli_query($link, "SELECT 1 AS b"))) {
45            printf("[%03d] [%d] %s\n", $offset + 4, mysqli_errno($link), mysqli_error($link));
46        } else {
47            mysqli_free_result($res);
48        }
49
50    }
51
52    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);
53    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);
54    func_test_mysqli_next_result($link, "DELETE FROM test WHERE id >= 100; SELECT 1 AS a; ", 11, 1);
55
56    mysqli_close($link);
57
58    try {
59        mysqli_next_result($link);
60    } catch (Error $exception) {
61        echo $exception->getMessage() . "\n";
62    }
63
64    print "done!";
65?>
66--CLEAN--
67<?php
68    require_once("clean_table.inc");
69?>
70--EXPECT--
71mysqli object is already closed
72done!
73