xref: /PHP-8.1/ext/pdo_mysql/tests/gh11550.phpt (revision ca5d4821)
1--TEST--
2Bug GH-11550 (MySQL Statement has a empty query result when the response field has changed, also Segmentation fault)
3--EXTENSIONS--
4pdo
5pdo_mysql
6--SKIPIF--
7<?php
8require_once __DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
9MySQLPDOTest::skip();
10?>
11--FILE--
12<?php
13require_once __DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
14$pdo = MySQLPDOTest::factory();
15
16$pdo->exec(<<<'SQL'
17CREATE TABLE `test_gh11550`  (
18  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
19  `name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
20  PRIMARY KEY (`id`) USING BTREE,
21  INDEX `name`(`name`) USING BTREE
22) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
23SQL);
24$pdo->exec(<<<'SQL'
25INSERT INTO `test_gh11550` (`name`) VALUES ('test1');
26SQL);
27
28$stmt = $pdo->prepare('select * from test_gh11550');
29var_dump('PDO-1:', $stmt->execute(), $stmt->fetchAll());
30
31$stmt->closeCursor(); // Optional. Segmentation fault (core dumped)
32
33$pdo->exec(<<<'SQL'
34ALTER TABLE `test_gh11550`
35ADD COLUMN `a` varchar(255) NOT NULL DEFAULT '';
36SQL);
37
38var_dump('PDO-2:', $stmt->execute(), $stmt->fetchAll());
39echo 'Done';
40?>
41--CLEAN--
42<?php
43require_once __DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc';
44$pdo = MySQLPDOTest::factory();
45$pdo->query('DROP TABLE IF EXISTS test_gh11550');
46?>
47--EXPECT--
48string(6) "PDO-1:"
49bool(true)
50array(1) {
51  [0]=>
52  array(4) {
53    ["id"]=>
54    int(1)
55    [0]=>
56    int(1)
57    ["name"]=>
58    string(5) "test1"
59    [1]=>
60    string(5) "test1"
61  }
62}
63string(6) "PDO-2:"
64bool(true)
65array(1) {
66  [0]=>
67  array(6) {
68    ["id"]=>
69    int(1)
70    [0]=>
71    int(1)
72    ["name"]=>
73    string(5) "test1"
74    [1]=>
75    string(5) "test1"
76    ["a"]=>
77    string(0) ""
78    [2]=>
79    string(0) ""
80  }
81}
82Done
83