1--TEST-- 2mysqli_fetch_field() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 13 $tmp = NULL; 14 $link = NULL; 15 16 // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test 17 if (!is_null($tmp = @mysqli_fetch_field())) 18 printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 19 20 if (!is_null($tmp = @mysqli_fetch_field($link))) 21 printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 22 23 require('table.inc'); 24 25 // Make sure that client, connection and result charsets are all the 26 // same. Not sure whether this is strictly necessary. 27 if (!mysqli_set_charset($link, 'utf8')) 28 printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link)); 29 30 $charsetInfo = mysqli_get_charset($link); 31 32 if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) { 33 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 34 } 35 36 /* ID column, binary charset */ 37 $tmp = mysqli_fetch_field($res); 38 var_dump($tmp); 39 40 /* label column, result set charset */ 41 $tmp = mysqli_fetch_field($res); 42 var_dump($tmp); 43 if ($tmp->charsetnr != $charsetInfo->number) { 44 printf("[004] Expecting charset %s/%d got %d\n", 45 $charsetInfo->charset, $charsetInfo->number, $tmp->charsetnr); 46 } 47 if ($tmp->length != $charsetInfo->max_length) { 48 printf("[005] Expecting length %d got %d\n", 49 $charsetInfo->max_length, $tmp->max_length); 50 } 51 if ($tmp->db != $db) { 52 printf("011] Expecting database '%s' got '%s'\n", 53 $db, $tmp->db); 54 } 55 56 var_dump(mysqli_fetch_field($res)); 57 58 mysqli_free_result($res); 59 60 // Read http://bugs.php.net/bug.php?id=42344 on defaults! 61 if (NULL !== ($tmp = mysqli_fetch_field($res))) 62 printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 63 64 if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) 65 printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 66 67 if (!mysqli_query($link, "CREATE TABLE test(id INT NOT NULL DEFAULT 1)")) 68 printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 69 70 if (!mysqli_query($link, "INSERT INTO test(id) VALUES (2)")) 71 printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 72 73 if (!$res = mysqli_query($link, "SELECT id as _default_test FROM test")) { 74 printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 75 } 76 var_dump(mysqli_fetch_assoc($res)); 77 /* binary */ 78 var_dump(mysqli_fetch_field($res)); 79 mysqli_free_result($res); 80 81 mysqli_close($link); 82 83 print "done!"; 84?> 85--CLEAN-- 86<?php 87 require_once("clean_table.inc"); 88?> 89--EXPECTF-- 90object(stdClass)#%d (13) { 91 [%u|b%"name"]=> 92 %unicode|string%(2) "ID" 93 [%u|b%"orgname"]=> 94 %unicode|string%(2) "id" 95 [%u|b%"table"]=> 96 %unicode|string%(4) "TEST" 97 [%u|b%"orgtable"]=> 98 %unicode|string%(%d) "%s" 99 [%u|b%"def"]=> 100 %unicode|string%(0) "" 101 [%u|b%"db"]=> 102 %unicode|string%(%d) "%s" 103 [%u|b%"catalog"]=> 104 %unicode|string%(%d) "%s" 105 [%u|b%"max_length"]=> 106 int(1) 107 [%u|b%"length"]=> 108 int(11) 109 [%u|b%"charsetnr"]=> 110 int(63) 111 [%u|b%"flags"]=> 112 int(49155) 113 [%u|b%"type"]=> 114 int(3) 115 [%u|b%"decimals"]=> 116 int(0) 117} 118object(stdClass)#%d (13) { 119 [%u|b%"name"]=> 120 %unicode|string%(5) "label" 121 [%u|b%"orgname"]=> 122 %unicode|string%(5) "label" 123 [%u|b%"table"]=> 124 %unicode|string%(4) "TEST" 125 [%u|b%"orgtable"]=> 126 %unicode|string%(%d) "%s" 127 [%u|b%"def"]=> 128 %unicode|string%(0) "" 129 [%u|b%"db"]=> 130 %unicode|string%(%d) "%s" 131 [%u|b%"catalog"]=> 132 %unicode|string%(%d) "%s" 133 [%u|b%"max_length"]=> 134 int(%d) 135 [%u|b%"length"]=> 136 int(%d) 137 [%u|b%"charsetnr"]=> 138 int(%d) 139 [%u|b%"flags"]=> 140 int(0) 141 [%u|b%"type"]=> 142 int(254) 143 [%u|b%"decimals"]=> 144 int(0) 145} 146bool(false) 147 148Warning: mysqli_fetch_field(): Couldn't fetch mysqli_result in %s on line %d 149array(1) { 150 [%u|b%"_default_test"]=> 151 %unicode|string%(1) "2" 152} 153object(stdClass)#%d (13) { 154 [%u|b%"name"]=> 155 %unicode|string%(13) "_default_test" 156 [%u|b%"orgname"]=> 157 %unicode|string%(2) "id" 158 [%u|b%"table"]=> 159 %unicode|string%(%d) "%s" 160 [%u|b%"orgtable"]=> 161 %unicode|string%(%d) "%s" 162 [%u|b%"def"]=> 163 %unicode|string%(0) "" 164 [%u|b%"db"]=> 165 %unicode|string%(%d) "%s" 166 [%u|b%"catalog"]=> 167 %unicode|string%(%d) "%s" 168 [%u|b%"max_length"]=> 169 int(1) 170 [%u|b%"length"]=> 171 int(11) 172 [%u|b%"charsetnr"]=> 173 int(63) 174 [%u|b%"flags"]=> 175 int(32769) 176 [%u|b%"type"]=> 177 int(3) 178 [%u|b%"decimals"]=> 179 int(0) 180} 181done! 182