xref: /PHP-8.0/ext/pdo_mysql/tests/bug_39858.phpt (revision 2df09b9b)
1--TEST--
2Bug #39858 (Lost connection to MySQL server during query by a repeated call stored proced)
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
6require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
7require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
8MySQLPDOTest::skip();
9$db = MySQLPDOTest::factory();
10
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 < 50000)
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
27function bug_39858($db) {
28
29    $db->exec("DROP PROCEDURE IF EXISTS p");
30    $db->exec("
31        CREATE PROCEDURE p()
32            NOT DETERMINISTIC
33            CONTAINS SQL
34            SQL SECURITY DEFINER
35            COMMENT ''
36        BEGIN
37            SELECT 2 * 2;
38        END;");
39
40    $stmt = $db->prepare("CALL p()");
41    $stmt->execute();
42    do {
43        var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
44    } while ($stmt->nextRowset());
45
46    $stmt = $db->prepare("CALL p()");
47    $stmt->execute();
48    do {
49        var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
50    } while ($stmt->nextRowset());
51    $stmt->closeCursor();
52
53}
54
55printf("Emulated Prepared Statements...\n");
56$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
57bug_39858($db);
58
59printf("Native Prepared Statements...\n");
60$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
61bug_39858($db);
62
63print "done!";
64?>
65--CLEAN--
66<?php
67require __DIR__ . '/mysql_pdo_test.inc';
68$db = MySQLPDOTest::factory();
69$db->exec("DROP PROCEDURE IF EXISTS p");
70?>
71--EXPECT--
72Emulated Prepared Statements...
73array(1) {
74  [0]=>
75  array(1) {
76    ["2 * 2"]=>
77    string(1) "4"
78  }
79}
80array(0) {
81}
82array(1) {
83  [0]=>
84  array(1) {
85    ["2 * 2"]=>
86    string(1) "4"
87  }
88}
89array(0) {
90}
91Native Prepared Statements...
92array(1) {
93  [0]=>
94  array(1) {
95    ["2 * 2"]=>
96    string(1) "4"
97  }
98}
99array(0) {
100}
101array(1) {
102  [0]=>
103  array(1) {
104    ["2 * 2"]=>
105    string(1) "4"
106  }
107}
108array(0) {
109}
110done!
111