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