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 (function_exists('mysqli_stmt_get_result')) { 67 68 if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p')) 69 printf("[019] [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); 70 71 if (mysqli_real_query($link, 'CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;')) { 72 // no result set, one output parameter 73 if (!$stmt = mysqli_prepare($link, 'CALL p(@version)')) 74 printf("[020] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 75 76 if (!mysqli_stmt_execute($stmt)) 77 printf("[021] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 78 79 if (!mysqli_stmt_close($stmt)) 80 printf("[022] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 81 82 if (!$stmt = mysqli_prepare($link, 'SELECT @version AS _version')) 83 printf("[023] Cannot prepare SELECT, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 84 85 if (!mysqli_stmt_execute($stmt)) 86 printf("[024] Cannot execute SELECT, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 87 88 if (!$res = mysqli_stmt_get_result($stmt)) 89 printf("[025] Cannot get result set, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 90 91 if ((!($row = mysqli_fetch_assoc($res))) || ($row['_version'] == "")) 92 printf("[026] Results seem wrong, got %s, [%d] %s\n", 93 $row['_version'], 94 mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 95 96 mysqli_free_result($res); 97 mysqli_stmt_close($stmt); 98 99 } else { 100 printf("[027] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); 101 } 102 103 } 104 105 if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p')) 106 printf("[028] [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); 107 108 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;')) { 109 // no result set, one input parameter, output parameter 110 // yes, I really do not want to bind input values... 111 if (!$stmt = mysqli_prepare($link, "CALL p('myversion', @version)")) 112 printf("[029] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 113 114 if (!mysqli_stmt_execute($stmt)) 115 printf("[030] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 116 117 if (!mysqli_stmt_close($stmt)) 118 printf("[031] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 119 120 if (!$stmt = mysqli_prepare($link, 'SELECT @version AS _version')) 121 printf("[032] Cannot prepare SELECT, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 122 123 if (!mysqli_stmt_execute($stmt)) 124 printf("[033] Cannot execute SELECT, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 125 126 $version = 'unknown'; 127 if (!mysqli_stmt_bind_result($stmt, $version) || 128 !mysqli_stmt_fetch($stmt)) 129 printf("[034] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 130 131 if ($version != "myversion") 132 printf("[035] Results seem wrong, got %s, [%d] %s\n", 133 $version, 134 mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 135 136 mysqli_stmt_free_result($stmt); 137 mysqli_stmt_close($stmt); 138 139 } else { 140 printf("[036] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); 141 } 142 143 if (!mysqli_query($link, 'DROP PROCEDURE IF EXISTS p')) 144 printf("[037] [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); 145 146 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;')) { 147 // no result set, one input parameter, output parameter 148 // yes, I really do not want to bind input values... 149 if (!$stmt = mysqli_prepare($link, 'CALL p(?, @version)')) 150 printf("[038] Cannot prepare CALL, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 151 152 $version = 'myversion'; 153 if (!mysqli_stmt_bind_param($stmt, 's', $version)) 154 printf("[039] Cannot bind input parameter, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 155 156 if (!mysqli_stmt_execute($stmt)) 157 printf("[040] Cannot execute CALL, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 158 159 if (!mysqli_stmt_close($stmt)) 160 printf("[041] Cannot close statement, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 161 162 if (!$stmt = mysqli_prepare($link, 'SELECT @version AS _version')) 163 printf("[042] Cannot prepare SELECT, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 164 165 if (!mysqli_stmt_execute($stmt)) 166 printf("[043] Cannot execute SELECT, [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 167 168 $version = 'unknown'; 169 if (!mysqli_stmt_bind_result($stmt, $version) || 170 !mysqli_stmt_fetch($stmt)) 171 printf("[044] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 172 173 if ($version !== "myversion") 174 printf("[045] Results seem wrong, got %s, [%d] %s\n", 175 $version, 176 mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 177 178 mysqli_stmt_free_result($stmt); 179 mysqli_stmt_close($stmt); 180 181 } else { 182 printf("[046] Cannot create SP, [%d] %s.\n", mysqli_errno($link), mysqli_error($link)); 183 } 184 185 mysqli_close($link); 186 print "done!"; 187?> 188--CLEAN-- 189<?php 190require_once "connect.inc"; 191if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 192 printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 193 194if (!mysqli_query($link, "DROP TABLE IF EXISTS test_bind_fetch")) 195 printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 196 197@mysqli_query($link, 'DROP PROCEDURE IF EXISTS p'); 198 199mysqli_close($link); 200?> 201--EXPECT-- 202done! 203