1--TEST-- 2mysqli_stmt_bind_param() - playing with references 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require('table.inc'); 12 13 function findRow($offset, $link, $id, $label) { 14 15 $sql = sprintf("SELECT id, label FROM test WHERE id = '%d' AND label = '%s'", 16 $id, $label); 17 if (!$res = mysqli_query($link, $sql)) { 18 printf("[%03d + 1] %s failed, [%d] %s\n", 19 $offset, $sql, mysqli_errno($link), mysqli_error($link)); 20 return false; 21 } 22 if (!$row = mysqli_fetch_assoc($res)) { 23 printf("[%03d + 2] fetch for %s failed, [%d] %s\n", 24 $offset, $sql, mysqli_errno($link), mysqli_error($link)); 25 return false; 26 } 27 28 mysqli_free_result($res); 29 if ($row['id'] != $id) { 30 printf("[%03d + 3] Expecting %s/%s got %s/%s\n", 31 $offset, gettype($id), $id, 32 gettype($row['id']), $row['id'] 33 ); 34 return false; 35 } 36 37 if ($row['label'] != $label) { 38 printf("[%03d + 4] Expecting %s/%s got %s/%s\n", 39 $offset, gettype($label), $label, 40 gettype($row['label']), $row['label'] 41 ); 42 return false; 43 } 44 45 $sql = sprintf("DELETE FROM test WHERE id = '%d' AND label = '%s'", 46 $id, $label); 47 if (!mysqli_query($link, $sql)) { 48 printf("[%03d + 5] %s failed, [%d] %s\n", 49 $offset, $sql, mysqli_errno($link), mysqli_error($link)); 50 return false; 51 } 52 53 return true; 54 } 55 // or we will get dups around [28] 56 mysqli_query($link, "ALTER TABLE test DROP PRIMARY KEY"); 57 58 $stmt = mysqli_stmt_init($link); 59 if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)")) 60 printf("[001] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 61 62 $id = 100; 63 $label = 'v'; 64 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label))) 65 printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 66 67 if (true !== mysqli_stmt_execute($stmt)) 68 printf("[003] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 69 // no need to check the return value, will bail and make EXPECTF fail if need be 70 findRow(4, $link, $id, $label); 71 72 $id++; 73 $label_ref = &$label; 74 $label = 'w'; 75 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label_ref))) 76 printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 77 78 if (true !== mysqli_stmt_execute($stmt)) 79 printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 80 findRow(7, $link, $id, $label_ref); 81 82 $id++; 83 $label_ref_ref = &$label_ref; 84 $label = 'x'; 85 86 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label_ref_ref))) 87 printf("[007] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 88 89 if (true !== mysqli_stmt_execute($stmt)) 90 printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 91 findRow(9, $link, $id, $label_ref_ref); 92 93 $id = 9; 94 $label = $id; 95 $label_num = &$label; 96 97 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label_num))) 98 printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 99 100 if (true !== mysqli_stmt_execute($stmt)) 101 printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 102 findRow(12, $link, $id, $label_num); 103 104 $label_num = &$id; 105 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label_num))) 106 printf("[013] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 107 108 if (true !== mysqli_stmt_execute($stmt)) 109 printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 110 findRow(15, $link, $id, $label_num); 111 112 $label = 9; 113 $id = &$label; 114 115 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label))) 116 printf("[015] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 117 118 if (true !== mysqli_stmt_execute($stmt)) 119 printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 120 findRow(17, $link, $id, $label); 121 122 $base = 9; 123 $id = &$base; 124 $label = &$id; 125 126 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label))) 127 printf("[018] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 128 129 if (true !== mysqli_stmt_execute($stmt)) 130 printf("[019] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 131 findRow(20, $link, $id, $label); 132 133 $id_ref = &$id; 134 $label_ref = &$label; 135 136 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id_ref, $label_ref))) 137 printf("[021] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 138 139 if (true !== mysqli_stmt_execute($stmt)) 140 printf("[022] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 141 findRow(23, $link, $id_ref, $label_ref); 142 143 $id_ref_ref = &$GLOBALS['id_ref']; 144 $label_ref_ref = &$GLOBALS['label_ref_ref']; 145 146 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id_ref_ref, $label_ref_ref))) 147 printf("[024] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 148 149 if (true !== mysqli_stmt_execute($stmt)) 150 printf("[025] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 151 findRow(26, $link, $id_ref_ref, $label_ref_ref); 152 153 unset($id); 154 unset($label); 155 $id = 102; 156 $label = new stdClass(); 157 $label->label = 'y'; 158 $id_ref = &$GLOBALS['id']; 159 $label_ref = &$label->label; 160 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id_ref, $label_ref))) 161 printf("[027] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 162 if (true !== @mysqli_stmt_execute($stmt)) 163 printf("[028] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 164 findRow(29, $link, $id_ref, $label_ref); 165 166 $id = 103; 167 $label_a = &$label_b; 168 $label_b = &$label_a; 169 $label_a = 'z'; 170 171 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label_b))) 172 printf("[030] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 173 174 if (true !== mysqli_stmt_execute($stmt)) 175 printf("[031] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 176 findRow(32, $link, $id, $label_b); 177 178 class foo { 179 public $foo; 180 function __construct() { 181 $this->foo = &$this->bar; 182 } 183 } 184 class bar extends foo { 185 public $bar = 'v'; 186 } 187 $bar = new bar(); 188 $id++; 189 $label = &$GLOBALS['bar']->foo; 190 191 if (true !== ($tmp = mysqli_stmt_bind_param($stmt, "is", $id, $label))) 192 printf("[033] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 193 194 if (true !== mysqli_stmt_execute($stmt)) 195 printf("[034] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 196 findRow(35, $link, $id, $label); 197 198 mysqli_stmt_close($stmt); 199 mysqli_close($link); 200 print "done!"; 201?> 202--CLEAN-- 203<?php 204 require_once("clean_table.inc"); 205?> 206--EXPECT-- 207done! 208