summaryrefslogtreecommitdiff
path: root/ext/mysqli/tests/ps_cursor_multiple_result_sets.phpt
blob: c4d80498b14c7c60fd63f8c23d0ac41e025fb674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
--TEST--
PS using cursor and returning multiple result sets
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
require_once(__DIR__ . '/connect.inc');

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$db = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
$db->query('DROP PROCEDURE IF EXISTS testPs');
$db->query(<<<'SQL'
CREATE PROCEDURE testPs() BEGIN
    DECLARE testCursor CURSOR FOR SELECT 'stuff';
    OPEN testCursor;
    CLOSE testCursor;
    SELECT 1 as a, 2 as b;
    SELECT 3 as a, 4 as b;
END
SQL
);

echo "use_result:\n";
$stmt = $db->prepare("call testPs()");
$stmt->execute();
$stmt->bind_result($v1, $v2);
while ($stmt->fetch()) {
    var_dump($v1, $v2);
}

$stmt->next_result();
$stmt->bind_result($v1, $v2);
while ($stmt->fetch()) {
    var_dump($v1, $v2);
}
$stmt->next_result();

echo "\nstore_result:\n";
$stmt = $db->prepare("call testPs()");
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($v1, $v2);
while ($stmt->fetch()) {
    var_dump($v1, $v2);
}

$stmt->next_result();
$stmt->store_result();
$stmt->bind_result($v1, $v2);
while ($stmt->fetch()) {
    var_dump($v1, $v2);
}
$stmt->next_result();

echo "\nget_result:\n";
$stmt = $db->prepare("call testPs()");
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    var_dump($row);
}

$stmt->next_result();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    var_dump($row);
}
$stmt->next_result();

?>
--CLEAN--
<?php
require_once 'connect.inc';
$link = new mysqli($host, $user, $passwd, $db, $port, $socket);
$link->query('DROP PROCEDURE IF EXISTS testPs');
$link->close();
?>
--EXPECT--
use_result:
int(1)
int(2)
int(3)
int(4)

store_result:
int(1)
int(2)
int(3)
int(4)

get_result:
array(2) {
  ["a"]=>
  int(1)
  ["b"]=>
  int(2)
}
array(2) {
  ["a"]=>
  int(3)
  ["b"]=>
  int(4)
}