1--TEST-- 2mysqli_field_seek() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 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 require('table.inc'); 60 61 // Make sure that client, connection and result charsets are all the 62 // same. Not sure whether this is strictly necessary. 63 if (!mysqli_set_charset($link, 'utf8')) 64 printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link)); 65 66 $charsetInfo = mysqli_get_charset($link); 67 68 if (!$res = mysqli_query($link, "SELECT id, label FROM test ORDER BY id LIMIT 1", MYSQLI_USE_RESULT)) { 69 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 70 } 71 72 try { 73 var_dump(mysqli_field_seek($res, -1)); 74 } catch (\ValueError $e) { 75 echo $e->getMessage() . \PHP_EOL; 76 } 77 var_dump(mysqli_fetch_field($res)); 78 var_dump(mysqli_field_seek($res, 0)); 79 var_dump(mysqli_fetch_field($res)); 80 var_dump(mysqli_field_seek($res, 1)); 81 82 $field = mysqli_fetch_field($res); 83 var_dump($field); 84 /* label column, result set charset */ 85 if ($field->charsetnr != $charsetInfo->number) { 86 printf("[004] Expecting charset %s/%d got %d\n", 87 $charsetInfo->charset, $charsetInfo->number, $field->charsetnr); 88 } 89 if ($field->length != $charsetInfo->max_length) { 90 printf("[005] Expecting length %d got %d\n", 91 $charsetInfo->max_length, $field->max_length); 92 } 93 94 var_dump(mysqli_field_tell($res)); 95 try { 96 var_dump(mysqli_field_seek($res, 2)); 97 } catch (\ValueError $e) { 98 echo $e->getMessage() . \PHP_EOL; 99 } 100 var_dump(mysqli_fetch_field($res)); 101 102 mysqli_free_result($res); 103 104 if (!$res = mysqli_query($link, "SELECT NULL as _null", MYSQLI_STORE_RESULT)) { 105 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 106 } 107 var_dump(mysqli_field_seek($res, 0)); 108 var_dump(mysqli_fetch_field($res)); 109 110 mysqli_free_result($res); 111 112 try { 113 mysqli_field_seek($res, 0); 114 } catch (Error $exception) { 115 echo $exception->getMessage() . "\n"; 116 } 117 118 mysqli_close($link); 119 print "done!"; 120?> 121--CLEAN-- 122<?php 123 require_once("clean_table.inc"); 124?> 125--EXPECTF-- 126mysqli_field_seek(): Argument #2 ($index) must be greater than or equal to 0 127object(stdClass)#%d (13) { 128 ["name"]=> 129 string(2) "id" 130 ["orgname"]=> 131 string(2) "id" 132 ["table"]=> 133 string(4) "test" 134 ["orgtable"]=> 135 string(4) "test" 136 ["def"]=> 137 string(0) "" 138 ["db"]=> 139 string(%d) "%s" 140 ["catalog"]=> 141 string(%d) "%s" 142 ["max_length"]=> 143 int(0) 144 ["length"]=> 145 int(11) 146 ["charsetnr"]=> 147 int(63) 148 ["flags"]=> 149 int(49155) 150 ["type"]=> 151 int(3) 152 ["decimals"]=> 153 int(0) 154} 155bool(true) 156object(stdClass)#%d (13) { 157 ["name"]=> 158 string(2) "id" 159 ["orgname"]=> 160 string(2) "id" 161 ["table"]=> 162 string(4) "test" 163 ["orgtable"]=> 164 string(4) "test" 165 ["def"]=> 166 string(0) "" 167 ["db"]=> 168 string(%d) "%s" 169 ["catalog"]=> 170 string(%d) "%s" 171 ["max_length"]=> 172 int(0) 173 ["length"]=> 174 int(11) 175 ["charsetnr"]=> 176 int(63) 177 ["flags"]=> 178 int(49155) 179 ["type"]=> 180 int(3) 181 ["decimals"]=> 182 int(0) 183} 184bool(true) 185object(stdClass)#%d (13) { 186 ["name"]=> 187 string(5) "label" 188 ["orgname"]=> 189 string(5) "label" 190 ["table"]=> 191 string(4) "test" 192 ["orgtable"]=> 193 string(4) "test" 194 ["def"]=> 195 string(0) "" 196 ["db"]=> 197 string(%d) "%s" 198 ["catalog"]=> 199 string(%d) "%s" 200 ["max_length"]=> 201 int(%d) 202 ["length"]=> 203 int(%d) 204 ["charsetnr"]=> 205 int(%d) 206 ["flags"]=> 207 int(0) 208 ["type"]=> 209 int(254) 210 ["decimals"]=> 211 int(0) 212} 213int(2) 214mysqli_field_seek(): Argument #2 ($index) must be less than the number of fields for this result set 215bool(false) 216bool(true) 217object(stdClass)#%d (13) { 218 ["name"]=> 219 string(5) "_null" 220 ["orgname"]=> 221 string(0) "" 222 ["table"]=> 223 string(0) "" 224 ["orgtable"]=> 225 string(0) "" 226 ["def"]=> 227 string(0) "" 228 ["db"]=> 229 string(0) "" 230 ["catalog"]=> 231 string(%d) "%s" 232 ["max_length"]=> 233 int(0) 234 ["length"]=> 235 int(0) 236 ["charsetnr"]=> 237 int(63) 238 ["flags"]=> 239 int(32896) 240 ["type"]=> 241 int(6) 242 ["decimals"]=> 243 int(0) 244} 245mysqli_result object is already closed 246done! 247