1--TEST--
2mysqli_stmt_execute() - Stored Procedures
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8require_once('connect.inc');
9if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
10    die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error()));
11}
12if (mysqli_get_server_version($link) <= 50000) {
13    die(sprintf('skip Needs MySQL 5.0+, found version %d.', mysqli_get_server_version($link)));
14}
15?>
16--FILE--
17<?php
18    require_once('connect.inc');
19    require_once('table.inc');
20
21    if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'))
22        printf("[009] [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
23
24    if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;')) {
25        /* no result set, one output parameter */
26        if (!$stmt = mysqli_prepare($link, 'CALL p(@version)'))
27            printf("[011] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
28
29        if (!mysqli_stmt_execute($stmt))
30            printf("[012] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
31
32        /* yes, I really want to call it twice! */
33        if (!mysqli_stmt_execute($stmt))
34            printf("[013] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
35
36        if (!mysqli_stmt_close($stmt))
37            printf("[014] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
38
39        if (!$stmt = mysqli_prepare($link, 'SELECT @version AS _version'))
40            printf("[015] Cannot prepare SELECT, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
41
42        if (!mysqli_stmt_execute($stmt))
43            printf("[016] Cannot execute SELECT, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
44
45        $version = 'unknown';
46        if (!mysqli_stmt_bind_result($stmt, $version) ||
47                !mysqli_stmt_fetch($stmt))
48            printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
49
50        if (($version == "unknown") || ($version == ""))
51            printf("[018] Results seem wrong, got %s, [%d] %s\n",
52                $version,
53                mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
54
55        mysqli_stmt_free_result($stmt);
56        mysqli_stmt_close($stmt);
57
58    } else {
59        printf("[010] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
60    }
61
62
63    if (function_exists('mysqli_stmt_get_result')) {
64
65        if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'))
66            printf("[019] [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
67
68        if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;')) {
69            // no result set, one output parameter
70            if (!$stmt = mysqli_prepare($link, 'CALL p(@version)'))
71                printf("[020] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
72
73            if (!mysqli_stmt_execute($stmt))
74                printf("[021] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
75
76            if (!mysqli_stmt_close($stmt))
77                printf("[022] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
78
79            if (!$stmt = mysqli_prepare($link, 'SELECT @version AS _version'))
80                printf("[023] Cannot prepare SELECT, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
81
82            if (!mysqli_stmt_execute($stmt))
83                printf("[024] Cannot execute SELECT, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
84
85            if (!$res = mysqli_stmt_get_result($stmt))
86                printf("[025] Cannot get result set, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
87
88            if ((!($row = mysqli_fetch_assoc($res))) || ($row['_version'] == ""))
89                printf("[026] Results seem wrong, got %s, [%d] %s\n",
90                    $row['_version'],
91                    mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
92
93            mysqli_free_result($res);
94            mysqli_stmt_close($stmt);
95
96        } else {
97            printf("[027] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
98        }
99
100    }
101
102    if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'))
103        printf("[028] [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
104
105    if (mysqli_real_query($link, 'CREATE PROCEDURE p(IN ver_in VARCHAR(25), OUT ver_out VARCHAR(25)) BEGIN SELECT ver_in INTO ver_out; END;')) {
106        // no result set, one input parameter, output parameter
107        // yes, I really do not want to bind input values...
108        if (!$stmt = mysqli_prepare($link, "CALL p('myversion', @version)"))
109            printf("[029] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
110
111        if (!mysqli_stmt_execute($stmt))
112            printf("[030] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
113
114        if (!mysqli_stmt_close($stmt))
115            printf("[031] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
116
117        if (!$stmt = mysqli_prepare($link, 'SELECT @version AS _version'))
118            printf("[032] Cannot prepare SELECT, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
119
120        if (!mysqli_stmt_execute($stmt))
121            printf("[033] Cannot execute SELECT, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
122
123        $version = 'unknown';
124        if (!mysqli_stmt_bind_result($stmt, $version) ||
125                !mysqli_stmt_fetch($stmt))
126            printf("[034] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
127
128        if ($version != "myversion")
129            printf("[035] Results seem wrong, got %s, [%d] %s\n",
130                $version,
131                mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
132
133        mysqli_stmt_free_result($stmt);
134        mysqli_stmt_close($stmt);
135
136    } else {
137        printf("[036] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
138    }
139
140    if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'))
141        printf("[037] [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
142
143    if (mysqli_real_query($link, 'CREATE PROCEDURE p(IN ver_in VARCHAR(25), OUT ver_out VARCHAR(25)) BEGIN SELECT ver_in INTO ver_out; END;')) {
144        // no result set, one input parameter, output parameter
145        // yes, I really do not want to bind input values...
146        if (!$stmt = mysqli_prepare($link, 'CALL p(?, @version)'))
147            printf("[038] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
148
149        $version = 'myversion';
150        if (!mysqli_stmt_bind_param($stmt, 's', $version))
151            printf("[039] Cannot bind input parameter, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
152
153        if (!mysqli_stmt_execute($stmt))
154            printf("[040] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
155
156        if (!mysqli_stmt_close($stmt))
157            printf("[041] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
158
159        if (!$stmt = mysqli_prepare($link, 'SELECT @version AS _version'))
160            printf("[042] Cannot prepare SELECT, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
161
162        if (!mysqli_stmt_execute($stmt))
163            printf("[043] Cannot execute SELECT, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
164
165        $version = 'unknown';
166        if (!mysqli_stmt_bind_result($stmt, $version) ||
167                !mysqli_stmt_fetch($stmt))
168            printf("[044] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
169
170        if ($version !== "myversion")
171            printf("[045] Results seem wrong, got %s, [%d] %s\n",
172                $version,
173                mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
174
175        mysqli_stmt_free_result($stmt);
176        mysqli_stmt_close($stmt);
177
178    } else {
179        printf("[046] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link));
180    }
181
182    mysqli_close($link);
183    print "done!";
184?>
185--CLEAN--
186<?php
187require_once("connect.inc");
188if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
189   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
190
191if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch"))
192    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
193
194@mysqli_query($link, 'DROP PROCEDURE IF EXISTS p');
195
196mysqli_close($link);
197?>
198--EXPECT--
199done!
200