xref: /PHP-8.1/ext/mysqli/tests/bug42548.phpt (revision b5a14e6c)
1--TEST--
2Bug #42548 PROCEDURE xxx can't return a result set in the given context (works in 5.2.3!!)
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8require_once('connect.inc');
9if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
10    die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error()));
11}
12if (mysqli_get_server_version($link) <= 50000) {
13    die(sprintf('skip Needs MySQL 5.0+, found version %d.', mysqli_get_server_version($link)));
14}
15?>
16--FILE--
17<?php
18require_once('connect.inc');
19
20$mysqli = mysqli_init();
21$mysqli->real_connect($host, $user, $passwd, $db, $port, $socket);
22if (mysqli_connect_errno()) {
23    printf("Connect failed: %s\n", mysqli_connect_error());
24    exit();
25}
26
27$mysqli->query("DROP PROCEDURE IF EXISTS p1") or die($mysqli->error);
28$mysqli->query("CREATE PROCEDURE p1() BEGIN SELECT 23; SELECT 42; END") or die($mysqli->error);
29
30if ($mysqli->multi_query("CALL p1();"))
31{
32    do
33    {
34        if ($objResult = $mysqli->store_result()) {
35            while ($row = $objResult->fetch_assoc()) {
36                print_r($row);
37            }
38            $objResult->close();
39            if ($mysqli->more_results()) {
40                print "----- next result -----------\n";
41            }
42        } else {
43            print "no results found\n";
44        }
45    } while ($mysqli->more_results() && $mysqli->next_result());
46} else {
47    print $mysqli->error;
48}
49
50$mysqli->query("DROP PROCEDURE p1") or die($mysqli->error);
51$mysqli->close();
52print "done!";
53?>
54--CLEAN--
55<?php
56require_once("connect.inc");
57if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
58   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
59
60mysqli_query($link, "DROP PROCEDURE IF EXISTS p1");
61
62mysqli_close($link);
63?>
64--EXPECT--
65Array
66(
67    [23] => 23
68)
69----- next result -----------
70Array
71(
72    [42] => 42
73)
74----- next result -----------
75no results found
76done!
77