xref: /PHP-5.6/ext/pdo_mysql/tests/bug_39858.phpt (revision a2d8ae9a)
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(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
7require_once(dirname(__FILE__) . 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[0] * 10000 + $matches[1] * 100 + $matches[2];
17if ($version < 50000)
18	die(sprintf("skip Need MySQL Server 5.0.0+, found %d.%02d.%02d (%d)\n",
19		$matches[0], $matches[1], $matches[2], $version));
20?>
21--XFAIL--
22nextRowset() problem with stored proc & emulation mode & mysqlnd
23--FILE--
24<?php
25require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
26$db = MySQLPDOTest::factory();
27$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
28
29function bug_39858($db) {
30
31	$db->exec("DROP PROCEDURE IF EXISTS p");
32	$db->exec("
33		CREATE PROCEDURE p()
34			NOT DETERMINISTIC
35			CONTAINS SQL
36			SQL SECURITY DEFINER
37			COMMENT ''
38		BEGIN
39			SELECT 2 * 2;
40		END;");
41
42	$stmt = $db->prepare("CALL p()");
43	$stmt->execute();
44	do {
45		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
46	} while ($stmt->nextRowset());
47
48	$stmt = $db->prepare("CALL p()");
49	$stmt->execute();
50	do {
51		var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
52	} while ($stmt->nextRowset());
53	$stmt->closeCursor();
54
55}
56
57printf("Emulated Prepared Statements...\n");
58$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
59bug_39858($db);
60
61printf("Native Prepared Statements...\n");
62$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
63bug_39858($db);
64
65print "done!";
66?>
67--CLEAN--
68<?php
69require dirname(__FILE__) . '/mysql_pdo_test.inc';
70$db = MySQLPDOTest::factory();
71$db->exec("DROP PROCEDURE IF EXISTS p");
72?>
73--EXPECTF--
74Emulated Prepared Statements...
75array(1) {
76  [0]=>
77  array(1) {
78    [%u|b%"2 * 2"]=>
79    %unicode|string%(1) "4"
80  }
81}
82array(1) {
83  [0]=>
84  array(1) {
85    [%u|b%"2 * 2"]=>
86    %unicode|string%(1) "4"
87  }
88}
89Native Prepared Statements...
90array(1) {
91  [0]=>
92  array(1) {
93    [%u|b%"2 * 2"]=>
94    %unicode|string%(1) "4"
95  }
96}
97array(1) {
98  [0]=>
99  array(1) {
100    [%u|b%"2 * 2"]=>
101    %unicode|string%(1) "4"
102  }
103}
104done!
105