1--TEST-- 2mysqli_field_seek() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 function mysqli_field_seek_flags($flags) { 12 13 $ret = ''; 14 15 if ($flags & MYSQLI_NOT_NULL_FLAG) 16 $ret .= 'MYSQLI_NOT_NULL_FLAG '; 17 18 if ($flags & MYSQLI_PRI_KEY_FLAG) 19 $ret .= 'MYSQLI_PRI_KEY_FLAG '; 20 21 if ($flags & MYSQLI_UNIQUE_KEY_FLAG) 22 $ret .= 'MYSQLI_UNIQUE_KEY_FLAG '; 23 24 if ($flags & MYSQLI_MULTIPLE_KEY_FLAG) 25 $ret .= 'MYSQLI_MULTIPLE_KEY_FLAG '; 26 27 if ($flags & MYSQLI_BLOB_FLAG) 28 $ret .= 'MYSQLI_BLOB_FLAG '; 29 30 if ($flags & MYSQLI_UNSIGNED_FLAG) 31 $ret .= 'MYSQLI_UNSIGNED_FLAG '; 32 33 if ($flags & MYSQLI_ZEROFILL_FLAG) 34 $ret .= 'MYSQLI_ZEROFILL_FLAG '; 35 36 if ($flags & MYSQLI_AUTO_INCREMENT_FLAG) 37 $ret .= 'MYSQLI_AUTO_INCREMENT_FLAG '; 38 39 if ($flags & MYSQLI_TIMESTAMP_FLAG) 40 $ret .= 'MYSQLI_TIMESTAMP_FLAG '; 41 42 if ($flags & MYSQLI_SET_FLAG) 43 $ret .= 'MYSQLI_SET_FLAG '; 44 45 if ($flags & MYSQLI_NUM_FLAG) 46 $ret .= 'MYSQLI_NUM_FLAG '; 47 48 if ($flags & MYSQLI_PART_KEY_FLAG) 49 $ret .= 'MYSQLI_PART_KEY_FLAG '; 50 51 if ($flags & MYSQLI_GROUP_FLAG) 52 $ret .= 'MYSQLI_GROUP_FLAG '; 53 54 return $ret; 55 } 56 57 require_once("connect.inc"); 58 59 $tmp = NULL; 60 $link = NULL; 61 62 if (!is_null($tmp = @mysqli_field_seek())) 63 printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 64 65 if (!is_null($tmp = @mysqli_field_seek($link))) 66 printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 67 68 require('table.inc'); 69 70 // Make sure that client, connection and result charsets are all the 71 // same. Not sure whether this is strictly necessary. 72 if (!mysqli_set_charset($link, 'utf8')) 73 printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link)); 74 75 $charsetInfo = mysqli_get_charset($link); 76 77 if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1", MYSQLI_USE_RESULT)) { 78 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 79 } 80 81 var_dump(mysqli_field_seek($res, -1)); 82 var_dump(mysqli_fetch_field($res)); 83 var_dump(mysqli_field_seek($res, 0)); 84 var_dump(mysqli_fetch_field($res)); 85 var_dump(mysqli_field_seek($res, 1)); 86 87 $field = mysqli_fetch_field($res); 88 var_dump($field); 89 /* label column, result set charset */ 90 if ($field->charsetnr != $charsetInfo->number) { 91 printf("[004] Expecting charset %s/%d got %d\n", 92 $charsetInfo->charset, $charsetInfo->number, $field->charsetnr); 93 } 94 if ($field->length != $charsetInfo->max_length) { 95 printf("[005] Expecting length %d got %d\n", 96 $charsetInfo->max_length, $field->max_length); 97 } 98 99 var_dump(mysqli_field_tell($res)); 100 var_dump(mysqli_field_seek($res, 2)); 101 var_dump(mysqli_fetch_field($res)); 102 var_dump(mysqli_field_seek($res, PHP_INT_MAX + 1)); 103 104 if (!is_null($tmp = @mysqli_field_seek($res, 0, "too many"))) 105 printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 106 107 mysqli_free_result($res); 108 109 if (!$res = mysqli_query($link, "SELECT NULL as _null", MYSQLI_STORE_RESULT)) { 110 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 111 } 112 var_dump(mysqli_field_seek($res, 0)); 113 var_dump(mysqli_fetch_field($res)); 114 115 mysqli_free_result($res); 116 117 var_dump(mysqli_field_seek($res, 0)); 118 119 mysqli_close($link); 120 print "done!"; 121?> 122--CLEAN-- 123<?php 124 require_once("clean_table.inc"); 125?> 126--EXPECTF-- 127Warning: mysqli_field_seek(): Invalid field offset in %s on line %d 128bool(false) 129object(stdClass)#%d (13) { 130 [%u|b%"name"]=> 131 %unicode|string%(2) "id" 132 [%u|b%"orgname"]=> 133 %unicode|string%(2) "id" 134 [%u|b%"table"]=> 135 %unicode|string%(4) "test" 136 [%u|b%"orgtable"]=> 137 %unicode|string%(4) "test" 138 [%u|b%"def"]=> 139 %unicode|string%(0) "" 140 [%u|b%"db"]=> 141 %unicode|string%(%d) "%s" 142 [%u|b%"catalog"]=> 143 %unicode|string%(%d) "%s" 144 [%u|b%"max_length"]=> 145 int(0) 146 [%u|b%"length"]=> 147 int(11) 148 [%u|b%"charsetnr"]=> 149 int(63) 150 [%u|b%"flags"]=> 151 int(49155) 152 [%u|b%"type"]=> 153 int(3) 154 [%u|b%"decimals"]=> 155 int(0) 156} 157bool(true) 158object(stdClass)#%d (13) { 159 [%u|b%"name"]=> 160 %unicode|string%(2) "id" 161 [%u|b%"orgname"]=> 162 %unicode|string%(2) "id" 163 [%u|b%"table"]=> 164 %unicode|string%(4) "test" 165 [%u|b%"orgtable"]=> 166 %unicode|string%(4) "test" 167 [%u|b%"def"]=> 168 %unicode|string%(0) "" 169 [%u|b%"db"]=> 170 %unicode|string%(%d) "%s" 171 [%u|b%"catalog"]=> 172 %unicode|string%(%d) "%s" 173 [%u|b%"max_length"]=> 174 int(0) 175 [%u|b%"length"]=> 176 int(11) 177 [%u|b%"charsetnr"]=> 178 int(63) 179 [%u|b%"flags"]=> 180 int(49155) 181 [%u|b%"type"]=> 182 int(3) 183 [%u|b%"decimals"]=> 184 int(0) 185} 186bool(true) 187object(stdClass)#%d (13) { 188 [%u|b%"name"]=> 189 %unicode|string%(5) "label" 190 [%u|b%"orgname"]=> 191 %unicode|string%(5) "label" 192 [%u|b%"table"]=> 193 %unicode|string%(4) "test" 194 [%u|b%"orgtable"]=> 195 %unicode|string%(4) "test" 196 [%u|b%"def"]=> 197 %unicode|string%(0) "" 198 [%u|b%"db"]=> 199 %unicode|string%(%d) "%s" 200 [%u|b%"catalog"]=> 201 %unicode|string%(%d) "%s" 202 [%u|b%"max_length"]=> 203 int(%d) 204 [%u|b%"length"]=> 205 int(%d) 206 [%u|b%"charsetnr"]=> 207 int(%d) 208 [%u|b%"flags"]=> 209 int(0) 210 [%u|b%"type"]=> 211 int(254) 212 [%u|b%"decimals"]=> 213 int(0) 214} 215int(2) 216 217Warning: mysqli_field_seek(): Invalid field offset in %s on line %d 218bool(false) 219bool(false) 220 221Warning: mysqli_field_seek() expects parameter 2 to be integer, float given in %s on line %d 222NULL 223bool(true) 224object(stdClass)#%d (13) { 225 [%u|b%"name"]=> 226 %unicode|string%(5) "_null" 227 [%u|b%"orgname"]=> 228 %unicode|string%(0) "" 229 [%u|b%"table"]=> 230 %unicode|string%(0) "" 231 [%u|b%"orgtable"]=> 232 %unicode|string%(0) "" 233 [%u|b%"def"]=> 234 %unicode|string%(0) "" 235 [%u|b%"db"]=> 236 %unicode|string%(0) "" 237 [%u|b%"catalog"]=> 238 %unicode|string%(%d) "%s" 239 [%u|b%"max_length"]=> 240 int(0) 241 [%u|b%"length"]=> 242 int(0) 243 [%u|b%"charsetnr"]=> 244 int(63) 245 [%u|b%"flags"]=> 246 int(32896) 247 [%u|b%"type"]=> 248 int(6) 249 [%u|b%"decimals"]=> 250 int(0) 251} 252 253Warning: mysqli_field_seek(): Couldn't fetch mysqli_result in %s on line %d 254NULL 255done! 256