xref: /PHP-8.2/ext/pdo_mysql/tests/bug_61411.phpt (revision 72f47c0c)
1--TEST--
2Bug #61411 (PDO Segfaults with PERSISTENT == TRUE && EMULATE_PREPARES == FALSE)
3--EXTENSIONS--
4pdo
5pdo_mysql
6--SKIPIF--
7<?php
8require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
9MySQLPDOTest::skip();
10$db = MySQLPDOTest::factory();
11
12$row = $db->query('SELECT VERSION() as _version')->fetch(PDO::FETCH_ASSOC);
13$matches = array();
14if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches))
15    die(sprintf("skip Cannot determine MySQL Server version\n"));
16
17$version = $matches[1] * 10000 + $matches[2] * 100 + $matches[3];
18if ($version < 40106)
19    die(sprintf("skip Need MySQL Server 4.1.6+, found %d.%02d.%02d (%d)\n",
20        $matches[1], $matches[2], $matches[3], $version));
21?>
22--FILE--
23<?php
24require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
25
26$attr	= getenv('PDOTEST_ATTR');
27if (!$attr) {
28    $attr = array();
29} else {
30    $attr = unserialize($attr);
31}
32$attr[PDO::ATTR_PERSISTENT] = true;
33$attr[PDO::ATTR_EMULATE_PREPARES] = false;
34$attr[PDO::ATTR_STRINGIFY_FETCHES] = true;
35putenv('PDOTEST_ATTR='.serialize($attr));
36
37$db = MySQLPDOTest::factory();
38
39$stmt = $db->prepare("SELECT 1");
40$stmt->execute();
41
42foreach ($stmt as $line) {
43    var_dump($line);
44}
45
46print "done!";
47?>
48--EXPECT--
49array(2) {
50  [1]=>
51  string(1) "1"
52  [0]=>
53  string(1) "1"
54}
55done!
56