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