1--TEST--
2PECL Bug #7976 (Calling stored procedure several times)
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
6require_once(__DIR__ . DIRECTORY_SEPARATOR . 'skipif.inc');
7require_once(__DIR__ . 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[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_once(__DIR__ . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
24$db = MySQLPDOTest::factory();
25
26function bug_pecl_7976($db) {
27
28    $db->exec('DROP PROCEDURE IF EXISTS p');
29    $db->exec('CREATE PROCEDURE p() BEGIN SELECT "1" AS _one; END;');
30
31    $stmt = $db->query('CALL p()');
32    var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
33    $stmt->closeCursor();
34
35    $stmt = $db->query('CALL p()');
36    var_dump($stmt->fetchAll(PDO::FETCH_ASSOC));
37    $stmt->closeCursor();
38
39}
40
41printf("Emulated...\n");
42$db = MySQLPDOTest::factory();
43$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
44bug_pecl_7976($db);
45
46printf("Native...\n");
47$db = MySQLPDOTest::factory();
48$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
49bug_pecl_7976($db);
50
51print "done!";
52?>
53--CLEAN--
54<?php
55require __DIR__ . '/mysql_pdo_test.inc';
56$db = MySQLPDOTest::factory();
57$db->exec('DROP PROCEDURE IF EXISTS p');
58?>
59--EXPECT--
60Emulated...
61array(1) {
62  [0]=>
63  array(1) {
64    ["_one"]=>
65    string(1) "1"
66  }
67}
68array(1) {
69  [0]=>
70  array(1) {
71    ["_one"]=>
72    string(1) "1"
73  }
74}
75Native...
76array(1) {
77  [0]=>
78  array(1) {
79    ["_one"]=>
80    string(1) "1"
81  }
82}
83array(1) {
84  [0]=>
85  array(1) {
86    ["_one"]=>
87    string(1) "1"
88  }
89}
90done!
91