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