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