1--TEST--
2mysqli_fetch_fields()
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    $fields = mysqli_fetch_fields($res);
28    foreach ($fields as $k => $field) {
29        var_dump($field);
30        switch ($k) {
31            case 1:
32                /* label column, result set charset */
33                if ($field->charsetnr != $charsetInfo->number) {
34                    printf("[004] Expecting charset %s/%d got %d\n",
35                        $charsetInfo->charset,
36                        $charsetInfo->number, $field->charsetnr);
37                }
38                if ($field->length != $charsetInfo->max_length) {
39                    printf("[005] Expecting length %d got %d\n",
40                        $charsetInfo->max_length,
41                        $field->max_length);
42                }
43                break;
44        }
45    }
46
47    mysqli_free_result($res);
48
49    try {
50        mysqli_fetch_fields($res);
51    } catch (Error $exception) {
52        echo $exception->getMessage() . "\n";
53    }
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  ["name"]=>
65  string(2) "ID"
66  ["orgname"]=>
67  string(2) "id"
68  ["table"]=>
69  string(4) "TEST"
70  ["orgtable"]=>
71  string(%d) "%s"
72  ["def"]=>
73  string(0) ""
74  ["db"]=>
75  string(%d) "%s"
76  ["catalog"]=>
77  string(%d) "%s"
78  ["max_length"]=>
79  int(1)
80  ["length"]=>
81  int(11)
82  ["charsetnr"]=>
83  int(63)
84  ["flags"]=>
85  int(49155)
86  ["type"]=>
87  int(3)
88  ["decimals"]=>
89  int(0)
90}
91object(stdClass)#%d (13) {
92  ["name"]=>
93  string(5) "label"
94  ["orgname"]=>
95  string(5) "label"
96  ["table"]=>
97  string(4) "TEST"
98  ["orgtable"]=>
99  string(%d) "%s"
100  ["def"]=>
101  string(0) ""
102  ["db"]=>
103  string(%d) "%s"
104  ["catalog"]=>
105  string(%d) "%s"
106  ["max_length"]=>
107  int(1)
108  ["length"]=>
109  int(%d)
110  ["charsetnr"]=>
111  int(%d)
112  ["flags"]=>
113  int(0)
114  ["type"]=>
115  int(254)
116  ["decimals"]=>
117  int(0)
118}
119mysqli_result object is already closed
120done!
121