xref: /PHP-8.2/ext/mysqli/tests/bug45019.phpt (revision 62d393b1)
1--TEST--
2Bug #45019 (Segmentation fault with SELECT ? and UNION)
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once("connect.inc");
12    require_once("table.inc");
13
14    // Regular (non-prepared) queries
15    print "Using CAST('somestring' AS CHAR)...\n";
16    if (!($res = $link->query("SELECT CAST('one' AS CHAR) AS column1 UNION SELECT CAST('three' AS CHAR) UNION SELECT CAST('two' AS CHAR)")))
17        printf("[001] [%d] %s\n", $link->errno, $link->error);
18
19    $data = array();
20    while ($row = $res->fetch_assoc()) {
21        $data[] = $row['column1'];
22        var_dump($row['column1']);
23    }
24    $res->free();
25
26    // Prepared Statements
27    if (!($stmt = $link->prepare("SELECT CAST('one' AS CHAR) AS column1 UNION SELECT CAST('three' AS CHAR) UNION SELECT CAST('two' AS CHAR)")))
28        printf("[002] [%d] %s\n", $link->errno, $link->error);
29
30    $column1 = null;
31    if (!$stmt->bind_result($column1) || !$stmt->execute())
32        printf("[003] [%d] %s\n", $stmt->errno, $stmt->error);
33
34    $index = 0;
35    while ($stmt->fetch()) {
36        if ($data[$index] != $column1) {
37            printf("[004] Row %d, expecting %s/%s got %s/%s\n",
38                $index + 1, gettype($data[$index]), $data[$index], gettype($column1), $column1);
39        }
40        $index++;
41    }
42    $stmt->close();
43
44    $link->close();
45
46    print "done!";
47?>
48--EXPECT--
49Using CAST('somestring' AS CHAR)...
50string(3) "one"
51string(5) "three"
52string(3) "two"
53done!
54