1--TEST-- 2mysqli_fetch_fields() 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_fields())) 18 printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 19 20 if (!is_null($tmp = @mysqli_fetch_fields($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 $fields = mysqli_fetch_fields($res); 37 foreach ($fields as $k => $field) { 38 var_dump($field); 39 switch ($k) { 40 case 1: 41 /* label column, result set charset */ 42 if ($field->charsetnr != $charsetInfo->number) { 43 printf("[004] Expecting charset %s/%d got %d\n", 44 $charsetInfo->charset, 45 $charsetInfo->number, $field->charsetnr); 46 } 47 if ($field->length != $charsetInfo->max_length) { 48 printf("[005] Expecting length %d got %d\n", 49 $charsetInfo->max_length, 50 $field->max_length); 51 } 52 break; 53 } 54 } 55 56 mysqli_free_result($res); 57 58 if (NULL !== ($tmp = mysqli_fetch_fields($res))) 59 printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 60 61 mysqli_close($link); 62 print "done!"; 63?> 64--CLEAN-- 65<?php 66 require_once("clean_table.inc"); 67?> 68--EXPECTF-- 69object(stdClass)#%d (13) { 70 [%u|b%"name"]=> 71 %unicode|string%(2) "ID" 72 [%u|b%"orgname"]=> 73 %unicode|string%(2) "id" 74 [%u|b%"table"]=> 75 %unicode|string%(4) "TEST" 76 [%u|b%"orgtable"]=> 77 %unicode|string%(%d) "%s" 78 [%u|b%"def"]=> 79 %unicode|string%(0) "" 80 [%u|b%"db"]=> 81 %unicode|string%(%d) "%s" 82 [%u|b%"catalog"]=> 83 %unicode|string%(%d) "%s" 84 [%u|b%"max_length"]=> 85 int(1) 86 [%u|b%"length"]=> 87 int(11) 88 [%u|b%"charsetnr"]=> 89 int(63) 90 [%u|b%"flags"]=> 91 int(49155) 92 [%u|b%"type"]=> 93 int(3) 94 [%u|b%"decimals"]=> 95 int(0) 96} 97object(stdClass)#%d (13) { 98 [%u|b%"name"]=> 99 %unicode|string%(5) "label" 100 [%u|b%"orgname"]=> 101 %unicode|string%(5) "label" 102 [%u|b%"table"]=> 103 %unicode|string%(4) "TEST" 104 [%u|b%"orgtable"]=> 105 %unicode|string%(%d) "%s" 106 [%u|b%"def"]=> 107 %unicode|string%(0) "" 108 [%u|b%"db"]=> 109 %unicode|string%(%d) "%s" 110 [%u|b%"catalog"]=> 111 %unicode|string%(%d) "%s" 112 [%u|b%"max_length"]=> 113 int(1) 114 [%u|b%"length"]=> 115 int(%d) 116 [%u|b%"charsetnr"]=> 117 int(%d) 118 [%u|b%"flags"]=> 119 int(0) 120 [%u|b%"type"]=> 121 int(254) 122 [%u|b%"decimals"]=> 123 int(0) 124} 125 126Warning: mysqli_fetch_fields(): Couldn't fetch mysqli_result in %s on line %d 127done! 128