1--TEST--
2mysqli_fetch_field()
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    require 'table.inc';
13    $mysqli = $link;
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('utf8'))
18        printf("[%d] %s\n", $mysqli->errno, $mysqli->errno);
19
20    $charsetInfo = $mysqli->get_charset();
21
22    if (!$res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
23        printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
24    }
25
26    var_dump($res->fetch_field());
27
28    $tmp = $res->fetch_field();
29    var_dump($tmp);
30    if ($tmp->charsetnr != $charsetInfo->number) {
31        printf("[005] Expecting charset %s/%d got %d\n",
32            $charsetInfo->charset, $charsetInfo->number, $tmp->charsetnr);
33    }
34    if ($tmp->db != $db) {
35        printf("[007] Expecting database '%s' got '%s'\n",
36          $db, $tmp->db);
37    }
38
39    var_dump($res->fetch_field());
40
41    $res->free_result();
42
43    try {
44        $res->fetch_field();
45    } catch (Error $exception) {
46        echo $exception->getMessage() . "\n";
47    }
48
49    $mysqli->close();
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(4) "test"
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(4) "test"
94  ["def"]=>
95  string(0) ""
96  ["db"]=>
97  string(%d) "%s"
98  ["catalog"]=>
99  string(%d) "%s"
100  ["max_length"]=>
101  int(%d)
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}
113bool(false)
114mysqli_result object is already closed
115done!
116