xref: /PHP-8.2/ext/mysqli/tests/bug44897.phpt (revision 62d393b1)
1--TEST--
2Bug #44879 (failed to prepare statement)
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'connect.inc';
8
9if (!$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
10    die(sprintf("skip Can't connect to MySQL Server - [%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
18    require_once("table.inc");
19
20    if (!$link->query('DROP PROCEDURE IF EXISTS p'))
21        printf("[001] [%d] %s\n", $link->errno, $link->error);
22
23    if (!$link->query('CREATE PROCEDURE p(IN new_id INT, IN new_label CHAR(1)) BEGIN INSERT INTO test(id, label) VALUES (new_id, new_label); SELECT new_label; END;'))
24        printf("[002] [%d] %s\n", $link->errno, $link->error);
25
26    $new_id = 100;
27    $new_label = 'z';
28
29    if (!$stmt = $link->prepare('CALL p(?, ?)'))
30        printf("[003] [%d] %s\n", $link->errno, $link->error);
31
32    if (!$stmt->bind_param('is', $new_id, $new_label) || !$stmt->execute())
33        printf("[004] [%d] %s\n", $stmt->errno, $stmt->error);
34
35    $out_new_label = null;
36    if (!$stmt->bind_result($out_new_label) || !$stmt->fetch())
37        printf("[005] [%d] %s\n", $stmt->errno, $stmt->error);
38
39    if ($out_new_label != $new_label)
40        printf("[006] IN value and returned value differ. Expecting %s/%s got %s/%s\n",
41            $new_label, gettype($new_label), $out_new_label, gettype($out_new_label));
42
43    $stmt->close();
44
45    $stmt2 = $link->prepare('SELECT label FROM test WHERE id = ?');
46    if (!is_object($stmt2)) {
47
48        printf("[007] Failed to create new statement object, [%d] %s\n",
49            $link->errno, $link->error);
50
51    } else {
52
53        if (!$stmt2->bind_param("i", $new_id) || !$stmt2->execute())
54            printf("[008] [%d] %s\n", $stmt2->errno, $stmt2->error);
55
56        $out_new_label = null;
57        if (!$stmt2->bind_result($out_new_label) || !$stmt2->fetch())
58            printf("[009] [%d] %s\n", $stmt2->errno, $stmt2->error);
59
60        if ($out_new_label != $new_label)
61            printf("[010] IN value and returned value differ. Expecting %s/%s got %s/%s\n",
62                $new_label, gettype($new_label), $out_new_label, gettype($out_new_label));
63
64    }
65
66    $link->close();
67
68    print "done!";
69?>
70--CLEAN--
71<?php
72require_once("connect.inc");
73if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
74   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
75
76if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
77    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
78
79mysqli_query($link, "DROP PROCEDURE IF EXISTS p");
80
81mysqli_close($link);
82?>
83--EXPECT--
84done!
85