1--TEST--
2mysqli_fetch_fields()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once("connect.inc");
12
13    // Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test
14
15    require('table.inc');
16
17    // Make sure that client, connection and result charsets are all the
18    // same. Not sure whether this is strictly necessary.
19    if (!mysqli_set_charset($link, 'utf8'))
20        printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link));
21
22    $charsetInfo = mysqli_get_charset($link);
23
24    if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
25        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
26    }
27
28    $fields = mysqli_fetch_fields($res);
29    foreach ($fields as $k => $field) {
30        var_dump($field);
31        switch ($k) {
32            case 1:
33                /* label column, result set charset */
34                if ($field->charsetnr != $charsetInfo->number) {
35                    printf("[004] Expecting charset %s/%d got %d\n",
36                        $charsetInfo->charset,
37                        $charsetInfo->number, $field->charsetnr);
38                }
39                break;
40        }
41    }
42
43    mysqli_free_result($res);
44
45    try {
46        mysqli_fetch_fields($res);
47    } catch (Error $exception) {
48        echo $exception->getMessage() . "\n";
49    }
50
51    mysqli_close($link);
52    print "done!";
53?>
54--CLEAN--
55<?php
56    require_once("clean_table.inc");
57?>
58--EXPECTF--
59object(stdClass)#%d (13) {
60  ["name"]=>
61  string(2) "ID"
62  ["orgname"]=>
63  string(2) "id"
64  ["table"]=>
65  string(4) "TEST"
66  ["orgtable"]=>
67  string(%d) "%s"
68  ["def"]=>
69  string(0) ""
70  ["db"]=>
71  string(%d) "%s"
72  ["catalog"]=>
73  string(%d) "%s"
74  ["max_length"]=>
75  int(0)
76  ["length"]=>
77  int(11)
78  ["charsetnr"]=>
79  int(63)
80  ["flags"]=>
81  int(49155)
82  ["type"]=>
83  int(3)
84  ["decimals"]=>
85  int(0)
86}
87object(stdClass)#%d (13) {
88  ["name"]=>
89  string(5) "label"
90  ["orgname"]=>
91  string(5) "label"
92  ["table"]=>
93  string(4) "TEST"
94  ["orgtable"]=>
95  string(%d) "%s"
96  ["def"]=>
97  string(0) ""
98  ["db"]=>
99  string(%d) "%s"
100  ["catalog"]=>
101  string(%d) "%s"
102  ["max_length"]=>
103  int(0)
104  ["length"]=>
105  int(%d)
106  ["charsetnr"]=>
107  int(%d)
108  ["flags"]=>
109  int(0)
110  ["type"]=>
111  int(254)
112  ["decimals"]=>
113  int(0)
114}
115mysqli_result object is already closed
116done!
117