1--TEST--
2$res->fetch_field_direct(s)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	require_once("connect.inc");
12
13	$tmp    = NULL;
14	$link   = NULL;
15
16	$mysqli = new mysqli();
17	$res = @new mysqli_result($mysqli);
18	if (!is_null($tmp = @$res->fetch_field_direct()))
19		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
20
21	require('table.inc');
22
23	if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
24		printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
25			$host, $user, $db, $port, $socket);
26
27	if (!$res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
28		printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
29	}
30
31	if (!is_null($tmp = @$res->fetch_field_direct()))
32		printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
33
34	if (!is_null($tmp = @$res->fetch_field_direct($link)))
35		printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
36
37	if (!is_null($tmp = @$res->fetch_field_direct($link, $link)))
38		printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
39
40	var_dump($res->fetch_field_direct(-1));
41	var_dump($res->fetch_field_direct(0));
42	var_dump($res->fetch_field_direct(2));
43
44	$res->free_result();
45
46	if (NULL !== ($tmp = $res->fetch_field_direct(0)))
47		printf("[007] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
48
49	$mysqli->close();
50	print "done!";
51?>
52--CLEAN--
53<?php
54	require_once("clean_table.inc");
55?>
56--EXPECTF--
57Warning: mysqli_result::fetch_field_direct(): Field offset is invalid for resultset in %s on line %d
58bool(false)
59object(stdClass)#%d (13) {
60  ["name"]=>
61  string(2) "ID"
62  ["orgname"]=>
63  string(2) "id"
64  ["table"]=>
65  string(4) "TEST"
66  ["orgtable"]=>
67  string(%d) "%s"
68  ["def"]=>
69  string(0) ""
70  ["db"]=>
71  string(%d) "%s"
72  ["catalog"]=>
73  string(%d) "%s"
74  ["max_length"]=>
75  int(%d)
76  ["length"]=>
77  int(11)
78  ["charsetnr"]=>
79  int(%d)
80  ["flags"]=>
81  int(%d)
82  ["type"]=>
83  int(%d)
84  ["decimals"]=>
85  int(%d)
86}
87
88Warning: mysqli_result::fetch_field_direct(): Field offset is invalid for resultset in %s on line %d
89bool(false)
90
91Warning: mysqli_result::fetch_field_direct(): Couldn't fetch mysqli_result in %s on line %d
92done!
93