bug_39858.phpt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. --TEST--
  2. Bug #39858 (Lost connection to MySQL server during query by a repeated call stored proced)
  3. --EXTENSIONS--
  4. pdo
  5. pdo_mysql
  6. --SKIPIF--
  7. <?php
  8. require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  9. MySQLPDOTest::skip();
  10. $db = MySQLPDOTest::factory();
  11. $row = $db->query('SELECT VERSION() as _version')->fetch(PDO::FETCH_ASSOC);
  12. $matches = array();
  13. if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches))
  14. die(sprintf("skip Cannot determine MySQL Server version\n"));
  15. $version = $matches[1] * 10000 + $matches[2] * 100 + $matches[3];
  16. if ($version < 50000)
  17. die(sprintf("skip Need MySQL Server 5.0.0+, found %d.%02d.%02d (%d)\n",
  18. $matches[1], $matches[2], $matches[3], $version));
  19. ?>
  20. --FILE--
  21. <?php
  22. require_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
  23. $db = MySQLPDOTest::factory();
  24. $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
  25. function bug_39858($db) {
  26. $db->exec("DROP PROCEDURE IF EXISTS p");
  27. $db->exec("
  28. CREATE PROCEDURE p()
  29. NOT DETERMINISTIC
  30. CONTAINS SQL
  31. SQL SECURITY DEFINER
  32. COMMENT ''
  33. BEGIN
  34. SELECT 2 * 2;
  35. END;");
  36. $stmt = $db->prepare("CALL p()");
  37. $stmt->execute();
  38. do {
  39. var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
  40. } while ($stmt->nextRowset());
  41. $stmt = $db->prepare("CALL p()");
  42. $stmt->execute();
  43. do {
  44. var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
  45. } while ($stmt->nextRowset());
  46. $stmt->closeCursor();
  47. }
  48. printf("Emulated Prepared Statements...\n");
  49. $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
  50. bug_39858($db);
  51. printf("Native Prepared Statements...\n");
  52. $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
  53. bug_39858($db);
  54. print "done!";
  55. ?>
  56. --CLEAN--
  57. <?php
  58. require __DIR__ . '/mysql_pdo_test.inc';
  59. $db = MySQLPDOTest::factory();
  60. $db->exec("DROP PROCEDURE IF EXISTS p");
  61. ?>
  62. --EXPECT--
  63. Emulated Prepared Statements...
  64. array(1) {
  65. [0]=>
  66. array(1) {
  67. ["2 * 2"]=>
  68. string(1) "4"
  69. }
  70. }
  71. array(0) {
  72. }
  73. array(1) {
  74. [0]=>
  75. array(1) {
  76. ["2 * 2"]=>
  77. string(1) "4"
  78. }
  79. }
  80. array(0) {
  81. }
  82. Native Prepared Statements...
  83. array(1) {
  84. [0]=>
  85. array(1) {
  86. ["2 * 2"]=>
  87. string(1) "4"
  88. }
  89. }
  90. array(0) {
  91. }
  92. array(1) {
  93. [0]=>
  94. array(1) {
  95. ["2 * 2"]=>
  96. string(1) "4"
  97. }
  98. }
  99. array(0) {
  100. }
  101. done!