xref: /PHP-8.2/ext/pdo_mysql/tests/bug_41997.phpt (revision b5a14e6c)
1--TEST--
2PDO MySQL Bug #41997 (stored procedure call returning single rowset blocks future queries)
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 < 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 __DIR__ . '/mysql_pdo_test.inc';
24$db = MySQLPDOTest::factory();
25$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
26
27$db->exec('DROP PROCEDURE IF EXISTS p');
28$db->exec('CREATE PROCEDURE p() BEGIN SELECT 1 AS "one"; END');
29
30$stmt = $db->query("CALL p()");
31do {
32    var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
33} while ($stmt->nextRowset());
34var_dump($stmt->errorInfo());
35
36$stmt = $db->query('SELECT 2 AS "two"');
37var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
38var_dump($stmt->errorInfo());
39print "done!";
40?>
41--CLEAN--
42<?php
43require_once __DIR__ . '/mysql_pdo_test.inc';
44$db = MySQLPDOTest::factory();
45$db->exec("DROP PROCEDURE IF EXISTS p");
46?>
47--EXPECT--
48array(1) {
49  [0]=>
50  array(1) {
51    ["one"]=>
52    string(1) "1"
53  }
54}
55array(0) {
56}
57array(3) {
58  [0]=>
59  string(5) "00000"
60  [1]=>
61  NULL
62  [2]=>
63  NULL
64}
65array(1) {
66  [0]=>
67  array(1) {
68    ["two"]=>
69    string(1) "2"
70  }
71}
72array(3) {
73  [0]=>
74  string(5) "00000"
75  [1]=>
76  NULL
77  [2]=>
78  NULL
79}
80done!
81