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