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--FILE-- 22<?php 23require_once(dirname(__FILE__) . 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 dirname(__FILE__) . '/mysql_pdo_test.inc'; 68$db = MySQLPDOTest::factory(); 69$db->exec("DROP PROCEDURE IF EXISTS p"); 70?> 71--EXPECTF-- 72Emulated Prepared Statements... 73array(1) { 74 [0]=> 75 array(1) { 76 [%u|b%"2 * 2"]=> 77 %unicode|string%(1) "4" 78 } 79} 80array(1) { 81 [0]=> 82 array(1) { 83 [%u|b%"2 * 2"]=> 84 %unicode|string%(1) "4" 85 } 86} 87Native Prepared Statements... 88array(1) { 89 [0]=> 90 array(1) { 91 [%u|b%"2 * 2"]=> 92 %unicode|string%(1) "4" 93 } 94} 95array(1) { 96 [0]=> 97 array(1) { 98 [%u|b%"2 * 2"]=> 99 %unicode|string%(1) "4" 100 } 101} 102done! 103