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