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