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