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