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  ["name"]=>
71  string(2) "ID"
72  ["orgname"]=>
73  string(2) "id"
74  ["table"]=>
75  string(4) "TEST"
76  ["orgtable"]=>
77  string(%d) "%s"
78  ["def"]=>
79  string(0) ""
80  ["db"]=>
81  string(%d) "%s"
82  ["catalog"]=>
83  string(%d) "%s"
84  ["max_length"]=>
85  int(1)
86  ["length"]=>
87  int(11)
88  ["charsetnr"]=>
89  int(63)
90  ["flags"]=>
91  int(49155)
92  ["type"]=>
93  int(3)
94  ["decimals"]=>
95  int(0)
96}
97object(stdClass)#%d (13) {
98  ["name"]=>
99  string(5) "label"
100  ["orgname"]=>
101  string(5) "label"
102  ["table"]=>
103  string(4) "TEST"
104  ["orgtable"]=>
105  string(%d) "%s"
106  ["def"]=>
107  string(0) ""
108  ["db"]=>
109  string(%d) "%s"
110  ["catalog"]=>
111  string(%d) "%s"
112  ["max_length"]=>
113  int(1)
114  ["length"]=>
115  int(%d)
116  ["charsetnr"]=>
117  int(%d)
118  ["flags"]=>
119  int(0)
120  ["type"]=>
121  int(254)
122  ["decimals"]=>
123  int(0)
124}
125
126Warning: mysqli_fetch_fields(): Couldn't fetch mysqli_result in %s on line %d
127done!
128