1--TEST--
2mysqli_fetch_field_direct()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("connect.inc");
11
12    require('table.inc');
13
14    if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
15        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
16    }
17
18    try {
19        var_dump(mysqli_fetch_field_direct($res, -1));
20    } catch (\ValueError $e) {
21        echo $e->getMessage() . \PHP_EOL;
22    }
23    var_dump(mysqli_fetch_field_direct($res, 0));
24
25    try {
26        var_dump(mysqli_fetch_field_direct($res, 2));
27    } catch (\ValueError $e) {
28        echo $e->getMessage() . \PHP_EOL;
29    }
30
31    mysqli_free_result($res);
32
33    try {
34        mysqli_fetch_field_direct($res, 0);
35    } catch (Error $exception) {
36        echo $exception->getMessage() . "\n";
37    }
38
39    mysqli_close($link);
40    print "done!";
41?>
42--CLEAN--
43<?php
44    require_once("clean_table.inc");
45?>
46--EXPECTF--
47mysqli_fetch_field_direct(): Argument #2 ($index) must be greater than or equal to 0
48object(stdClass)#%d (13) {
49  ["name"]=>
50  string(2) "ID"
51  ["orgname"]=>
52  string(2) "id"
53  ["table"]=>
54  string(4) "TEST"
55  ["orgtable"]=>
56  string(4) "test"
57  ["def"]=>
58  string(0) ""
59  ["db"]=>
60  string(%d) "%s"
61  ["catalog"]=>
62  string(%d) "%s"
63  ["max_length"]=>
64  int(%d)
65  ["length"]=>
66  int(%d)
67  ["charsetnr"]=>
68  int(%d)
69  ["flags"]=>
70  int(%d)
71  ["type"]=>
72  int(%d)
73  ["decimals"]=>
74  int(%d)
75}
76mysqli_fetch_field_direct(): Argument #2 ($index) must be less than the number of fields for this result set
77mysqli_result object is already closed
78done!
79