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