xref: /PHP-8.2/ext/mysqli/tests/bug72489.phpt (revision b5a14e6c)
1--TEST--
2Bug #72489 (PHP Crashes When Modifying Array Containing MySQLi Result Data)
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11
12require_once("connect.inc");
13if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
14    printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
15}
16
17if (!$link->query("DROP TABLE IF EXISTS bug72489")) {
18    printf("[002] [%d] %s\n", $link->errno, $link->error);
19}
20
21if (!$link->query("CREATE TABLE bug72489 (id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, code VARCHAR(30) NOT NULL)")) {
22    printf("[003] [%d] %s\n", $link->errno, $link->error);
23}
24
25$seedSQL = "INSERT INTO bug72489 (`code`) VALUES ('code1'), ('code2'), ('code3');";
26if (!$link->query($seedSQL)) {
27    printf("[004] [%d] %s\n", $link->errno, $link->error);
28}
29
30$subRow = array();
31
32if (!$stmt = $link->prepare("SELECT id, code FROM bug72489")) {
33    printf("[005] [%d] %s\n", $link->errno, $link->error);
34}
35
36$stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_READ_ONLY);
37if (!$stmt->bind_result($subRow['id'], $subRow['code']) || !$stmt->execute()) {
38    printf("[006] [%d] %s\n", $link->errno, $link->error);
39}
40
41while ($stmt->fetch()) {
42    $testArray = array('id' => 1);
43    $subRow['code'] = $testArray;
44}
45
46echo "Finished 1\n";
47
48$newArray = array();
49
50echo "Finished 2\n";
51
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
59if (!mysqli_query($link, "DROP TABLE IF EXISTS bug72489"))
60    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
61
62mysqli_close($link);
63?>
64--EXPECT--
65Finished 1
66Finished 2
67