xref: /PHP-8.2/ext/pdo_mysql/tests/bug_41125.phpt (revision b5a14e6c)
1--TEST--
2Bug #41125 (PDO mysql + quote() + prepare() can result in segfault)
3--EXTENSIONS--
4pdo_mysql
5--SKIPIF--
6<?php
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9
10$db = MySQLPDOTest::factory();
11$row = $db->query('SELECT VERSION() as _version')->fetch(PDO::FETCH_ASSOC);
12$matches = array();
13if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches))
14    die(sprintf("skip Cannot determine MySQL Server version\n"));
15
16$version = $matches[1] * 10000 + $matches[2] * 100 + $matches[3];
17if ($version < 40100)
18    die(sprintf("skip Need MySQL Server 5.0.0+, found %d.%02d.%02d (%d)\n",
19        $matches[1], $matches[2], $matches[3], $version));
20?>
21--FILE--
22<?php
23require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
24$db = MySQLPDOTest::factory();
25$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
26$db->exec("DROP TABLE IF EXISTS test");
27
28// And now allow the evil to do his work
29$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
30$sql = "CREATE TABLE IF NOT EXISTS test(id INT); INSERT INTO test(id) VALUES (1); SELECT * FROM test; INSERT INTO test(id) VALUES (2); SELECT * FROM test;";
31$stmt = $db->query($sql);
32do {
33    var_dump($stmt->fetchAll());
34} while ($stmt->nextRowset());
35
36print "done!";
37?>
38--CLEAN--
39<?php
40require __DIR__ . '/mysql_pdo_test.inc';
41$db = MySQLPDOTest::factory();
42$db->exec("DROP TABLE IF EXISTS test");
43?>
44--EXPECT--
45array(0) {
46}
47array(0) {
48}
49array(1) {
50  [0]=>
51  array(2) {
52    ["id"]=>
53    string(1) "1"
54    [0]=>
55    string(1) "1"
56  }
57}
58array(0) {
59}
60array(2) {
61  [0]=>
62  array(2) {
63    ["id"]=>
64    string(1) "1"
65    [0]=>
66    string(1) "1"
67  }
68  [1]=>
69  array(2) {
70    ["id"]=>
71    string(1) "2"
72    [0]=>
73    string(1) "2"
74  }
75}
76done!
77