1--TEST--
2PS using cursor and returning multiple result sets
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10require_once(__DIR__ . '/connect.inc');
11
12mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
13$db = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
14$db->query('DROP PROCEDURE IF EXISTS testPs');
15$db->query(<<<'SQL'
16CREATE PROCEDURE testPs() BEGIN
17    DECLARE testCursor CURSOR FOR SELECT 'stuff';
18    OPEN testCursor;
19    CLOSE testCursor;
20    SELECT 1 as a, 2 as b;
21    SELECT 3 as a, 4 as b;
22END
23SQL
24);
25
26echo "use_result:\n";
27$stmt = $db->prepare("call testPs()");
28$stmt->execute();
29$stmt->bind_result($v1, $v2);
30while ($stmt->fetch()) {
31    var_dump($v1, $v2);
32}
33
34$stmt->next_result();
35$stmt->bind_result($v1, $v2);
36while ($stmt->fetch()) {
37    var_dump($v1, $v2);
38}
39$stmt->next_result();
40
41echo "\nstore_result:\n";
42$stmt = $db->prepare("call testPs()");
43$stmt->execute();
44$stmt->store_result();
45$stmt->bind_result($v1, $v2);
46while ($stmt->fetch()) {
47    var_dump($v1, $v2);
48}
49
50$stmt->next_result();
51$stmt->store_result();
52$stmt->bind_result($v1, $v2);
53while ($stmt->fetch()) {
54    var_dump($v1, $v2);
55}
56$stmt->next_result();
57
58echo "\nget_result:\n";
59$stmt = $db->prepare("call testPs()");
60$stmt->execute();
61$result = $stmt->get_result();
62while ($row = $result->fetch_assoc()) {
63    var_dump($row);
64}
65
66$stmt->next_result();
67$result = $stmt->get_result();
68while ($row = $result->fetch_assoc()) {
69    var_dump($row);
70}
71$stmt->next_result();
72
73?>
74--EXPECT--
75use_result:
76int(1)
77int(2)
78int(3)
79int(4)
80
81store_result:
82int(1)
83int(2)
84int(3)
85int(4)
86
87get_result:
88array(2) {
89  ["a"]=>
90  int(1)
91  ["b"]=>
92  int(2)
93}
94array(2) {
95  ["a"]=>
96  int(3)
97  ["b"]=>
98  int(4)
99}
100