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