1--TEST--
2Multiple result set with PS
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'skipifconnectfailure.inc';
8?>
9--FILE--
10<?php
11    require 'table.inc';
12
13    $stmt = mysqli_stmt_init($link);
14    if (!$link->query('DROP PROCEDURE IF EXISTS p123')) {
15        printf("[001] [%d] %s\n", $link->error, $link->errno);
16    }
17
18    if (!$link->query("CREATE PROCEDURE p123() BEGIN SELECT id+12, CONCAT_WS('-',label,'ahoi') FROM test ORDER BY id LIMIT 1; SELECT id + 42, CONCAT_WS('---',label, label) FROM test ORDER BY id LIMIT 1; END")) {
19        printf("[002] [%d] %s\n", $link->error, $link->errno);
20    }
21
22    if (!($stmt = $link->prepare("CALL p123"))) {
23        printf("[003] [%d] %s\n", $stmt->error, $stmt->errno);
24    }
25
26    if (!$stmt->execute()) {
27        printf("[005] [%d] %s\n", $stmt->error, $stmt->errno);
28    }
29
30    $c_id = NULL;
31    $c_label = NULL;
32    if (!$stmt->bind_result($c_id, $c_label)) {
33        printf("[004] [%d] %s\n", $stmt->error, $stmt->errno);
34    }
35    var_dump("pre:",$c_id, $c_label);
36
37    if (!$stmt->fetch()) {
38        printf("[006] [%d] %s\n", $stmt->error, $stmt->errno);
39    }
40
41    var_dump("post:",$c_id, $c_label);
42
43    if ($stmt->fetch()) {
44        printf("[007] Shouldn't have fetched anything\n");
45        var_dump($c_id, $c_label);
46    }
47
48    if ($stmt->fetch()) {
49        printf("[008] No more rows expected\n");
50    }
51
52    if (!$stmt->more_results()) {
53        printf("[009] Expected more results\n");
54    } else {
55        var_dump("[009] next_result:", $stmt->next_result());
56    }
57
58    if (!$stmt->bind_result($c_id, $c_label)) {
59        printf("[010] [%d] %s\n", $stmt->error, $stmt->errno);
60    }
61    var_dump("pre:",$c_id, $c_label);
62
63    if (!$stmt->fetch()) {
64        printf("[011] [%d] %s\n", $stmt->error, $stmt->errno);
65    }
66
67    var_dump("post:",$c_id, $c_label);
68
69    if ($stmt->fetch()) {
70        printf("[012] No more rows expected\n");
71    }
72
73    if (!$stmt->more_results()) {
74        printf("[013] Expected more results\n");
75    } else {
76        var_dump("[013] next_result:", $stmt->next_result());
77    }
78
79    if ($stmt->more_results()) {
80        printf("[014] No more results expected\n");
81    } else {
82        printf("[014] No result, as expected\n");
83    }
84
85    $stmt->close();
86    $link->close();
87
88
89    echo "done";
90?>
91--CLEAN--
92<?php
93require_once 'connect.inc';
94$link = new mysqli($host, $user, $passwd, $db, $port, $socket);
95$link->query('DROP PROCEDURE IF EXISTS p123');
96$link->close();
97?>
98--EXPECT--
99string(4) "pre:"
100NULL
101NULL
102string(5) "post:"
103int(13)
104string(6) "a-ahoi"
105string(18) "[009] next_result:"
106bool(true)
107string(4) "pre:"
108int(13)
109string(6) "a-ahoi"
110string(5) "post:"
111int(43)
112string(5) "a---a"
113string(18) "[013] next_result:"
114bool(true)
115[014] No result, as expected
116done
117