1--TEST-- 2mysqli_stmt_bind_param used with call_user_func_array() (see also bug #43568) 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 require('connect.inc'); 11 require('table.inc'); 12 13 if (!$stmt = mysqli_stmt_init($link)) 14 printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 15 16 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 17 printf("[002] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 18 19 $id = 1; 20 if (!mysqli_stmt_bind_param($stmt, 'i', $id) || 21 !mysqli_stmt_execute($stmt)) 22 printf("[003] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 23 24 $id = $label = null; 25 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 26 (true !== mysqli_stmt_fetch($stmt))) 27 printf("[004] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 28 29 print "Regular, procedural, using variables\n"; 30 var_dump($id); 31 var_dump($label); 32 33 mysqli_stmt_close($stmt); 34 if (!$stmt = mysqli_stmt_init($link)) 35 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 36 37 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 38 printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 39 40 $types = 'i'; 41 $id = 1; 42 $params = array( 43 0 => &$stmt, 44 1 => &$types, 45 2 => &$id 46 ); 47 if (!call_user_func_array('mysqli_stmt_bind_param', $params)) 48 printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 49 50 if (!mysqli_stmt_execute($stmt)) 51 printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 52 53 $id = $label = null; 54 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 55 (true !== mysqli_stmt_fetch($stmt))) 56 printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 57 58 print "Call user func, procedural, using references for everything\n"; 59 var_dump($id); 60 var_dump($label); 61 62 mysqli_stmt_close($stmt); 63 if (!$stmt = mysqli_stmt_init($link)) 64 printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 65 66 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 67 printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 68 69 $types = 'i'; 70 $id = 1; 71 $params = array( 72 0 => &$types, 73 1 => &$id 74 ); 75 if (!call_user_func_array(array($stmt, 'bind_param'), $params)) 76 printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 77 78 if (!mysqli_stmt_execute($stmt)) 79 printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 80 81 $id = $label = null; 82 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 83 (true !== mysqli_stmt_fetch($stmt))) 84 printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 85 86 print "Call user func, object oriented, using references for everything\n"; 87 var_dump($id); 88 var_dump($label); 89 90 mysqli_stmt_close($stmt); 91 if (!$stmt = mysqli_stmt_init($link)) 92 printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 93 94 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 95 printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 96 97 $types = 'i'; 98 $id = 1; 99 $params = array( 100 0 => $types, 101 1 => &$id 102 ); 103 if (!call_user_func_array(array($stmt, 'bind_param'), $params)) 104 printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 105 106 if (!mysqli_stmt_execute($stmt)) 107 printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 108 109 $id = $label = null; 110 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 111 (true !== mysqli_stmt_fetch($stmt))) 112 printf("[019] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 113 114 print "Call user func, object oriented, using variable for types. using references for bound parameter\n"; 115 var_dump($id); 116 var_dump($label); 117 118 mysqli_stmt_close($stmt); 119 if (!$stmt = mysqli_stmt_init($link)) 120 printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 121 122 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 123 printf("[021] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 124 125 $id = 1; 126 $params = array( 127 0 => 'i', 128 1 => &$id 129 ); 130 if (!call_user_func_array(array($stmt, 'bind_param'), $params)) 131 printf("[022] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 132 133 if (!mysqli_stmt_execute($stmt)) 134 printf("[023] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 135 136 $id = $label = null; 137 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 138 (true !== mysqli_stmt_fetch($stmt))) 139 printf("[024] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 140 141 print "Call user func, object oriented, using constant for types. using references for bound parameter\n"; 142 var_dump($id); 143 var_dump($label); 144 145 mysqli_stmt_close($stmt); 146 if (!$stmt = mysqli_stmt_init($link)) 147 printf("[025] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 148 149 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 150 printf("[026] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 151 152 $types = 'i'; 153 $id = 1; 154 $params = array( 155 0 => &$stmt, 156 1 => $types, 157 2 => &$id 158 ); 159 if (!call_user_func_array('mysqli_stmt_bind_param', $params)) 160 printf("[027] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 161 162 if (!mysqli_stmt_execute($stmt)) 163 printf("[028] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 164 165 $id = $label = null; 166 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 167 (true !== mysqli_stmt_fetch($stmt))) 168 printf("[029] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 169 170 print "Call user func, procedural, using references for everything but using variable for types\n"; 171 var_dump($id); 172 var_dump($label); 173 174 mysqli_stmt_close($stmt); 175 if (!$stmt = mysqli_stmt_init($link)) 176 printf("[025] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 177 178 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 179 printf("[026] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 180 181 $types = 'i'; 182 $id = 1; 183 $params = array( 184 0 => $stmt, 185 1 => $types, 186 2 => &$id 187 ); 188 if (!call_user_func_array('mysqli_stmt_bind_param', $params)) 189 printf("[027] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 190 191 if (!mysqli_stmt_execute($stmt)) 192 printf("[028] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 193 194 $id = $label = null; 195 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 196 (true !== mysqli_stmt_fetch($stmt))) 197 printf("[029] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 198 199 print "Call user func, procedural, using references for bound parameter, using variables for resource and types\n"; 200 var_dump($id); 201 var_dump($label); 202 203 mysqli_stmt_close($stmt); 204 if (!$stmt = mysqli_stmt_init($link)) 205 printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 206 207 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 208 printf("[031] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 209 210 $types = 'i'; 211 $id = 1; 212 $params = array( 213 0 => $stmt, 214 1 => $types, 215 2 => &$id 216 ); 217 if (!call_user_func_array('mysqli_stmt_bind_param', $params)) 218 printf("[032] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 219 220 if (!mysqli_stmt_execute($stmt)) 221 printf("[033] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 222 223 $id = $label = null; 224 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 225 (true !== mysqli_stmt_fetch($stmt))) 226 printf("[034] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 227 228 print "Call user func, procedural, using references for bound parameter, using variables for resource and types\n"; 229 var_dump($id); 230 var_dump($label); 231 232 mysqli_stmt_close($stmt); 233 if (!$stmt = mysqli_stmt_init($link)) 234 printf("[035] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 235 236 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 237 printf("[036] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 238 239 $id = 1; 240 $params = array( 241 0 => $stmt, 242 1 => 'i', 243 2 => &$id 244 ); 245 if (!call_user_func_array('mysqli_stmt_bind_param', $params)) 246 printf("[037] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 247 248 if (!mysqli_stmt_execute($stmt)) 249 printf("[038] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 250 251 $id = $label = null; 252 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 253 (true !== mysqli_stmt_fetch($stmt))) 254 printf("[039] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 255 256 print "Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types\n"; 257 var_dump($id); 258 var_dump($label); 259 260 mysqli_stmt_close($stmt); 261 if (!$stmt = mysqli_stmt_init($link)) 262 printf("[040] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 263 264 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 265 printf("[041] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 266 267 $id = 1; 268 if (!call_user_func_array('mysqli_stmt_bind_param', array($stmt, 'i', &$id))) 269 printf("[042] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 270 271 if (!mysqli_stmt_execute($stmt)) 272 printf("[043] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 273 274 $id = $label = null; 275 if (!mysqli_stmt_bind_result($stmt, $id, $label) || 276 (true !== mysqli_stmt_fetch($stmt))) 277 printf("[044] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 278 279 print "Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types, array\n"; 280 var_dump($id); 281 var_dump($label); 282 283 // 284 // Any of those shall fail - see also bugs.php.net/43568 285 // 286 mysqli_stmt_close($stmt); 287 if (!$stmt = mysqli_stmt_init($link)) 288 printf("[045] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 289 290 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 291 printf("[046] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 292 293 $id = 1; 294 $params = array( 295 0 => 'i', 296 1 => &$id 297 ); 298 if (!call_user_func_array(array($stmt, 'bind_param'), $params)) 299 printf("[047] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 300 301 if (!mysqli_stmt_execute($stmt)) 302 printf("[048] [%d] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement)\n", mysqli_stmt_errno($stmt)); 303 304 mysqli_stmt_close($stmt); 305 if (!$stmt = mysqli_stmt_init($link)) 306 printf("[049] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 307 308 if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?')) 309 printf("[050] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 310 311 $types = 'i'; 312 $id = 1; 313 $params = array( 314 0 => $stmt, 315 1 => 'i', 316 2 => &$id 317 ); 318 if (!call_user_func_array('mysqli_stmt_bind_param', $params)) 319 printf("[051] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 320 321 if (!mysqli_stmt_execute($stmt)) 322 printf("[052] [%d] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement)\n", mysqli_stmt_errno($stmt)); 323 324 print "done!"; 325?> 326--CLEAN-- 327<?php 328 require_once("clean_table.inc"); 329?> 330--EXPECT-- 331Regular, procedural, using variables 332int(1) 333string(1) "a" 334Call user func, procedural, using references for everything 335int(1) 336string(1) "a" 337Call user func, object oriented, using references for everything 338int(1) 339string(1) "a" 340Call user func, object oriented, using variable for types. using references for bound parameter 341int(1) 342string(1) "a" 343Call user func, object oriented, using constant for types. using references for bound parameter 344int(1) 345string(1) "a" 346Call user func, procedural, using references for everything but using variable for types 347int(1) 348string(1) "a" 349Call user func, procedural, using references for bound parameter, using variables for resource and types 350int(1) 351string(1) "a" 352Call user func, procedural, using references for bound parameter, using variables for resource and types 353int(1) 354string(1) "a" 355Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types 356int(1) 357string(1) "a" 358Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types, array 359int(1) 360string(1) "a" 361done! 362