1--TEST--
2mysqli_fetch_field()
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	// Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test
17	$mysqli = new mysqli();
18	$res = @new mysqli_result($mysqli);
19	if (!is_null($tmp = @$res->fetch_field()))
20		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
21
22	require('table.inc');
23	if (!$mysqli = new 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 (!is_null($tmp = @$res->fetch_field($link)))
28		printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
29
30	// Make sure that client, connection and result charsets are all the
31	// same. Not sure whether this is strictly necessary.
32	if (!$mysqli->set_charset('utf8'))
33		printf("[%d] %s\n", $mysqli->errno, $mysqli->errno);
34
35	$charsetInfo = $mysqli->get_charset();
36
37	if (!$res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1")) {
38		printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
39	}
40
41	var_dump($res->fetch_field());
42
43	$tmp = $res->fetch_field();
44	var_dump($tmp);
45	if ($tmp->charsetnr != $charsetInfo->number) {
46		printf("[005] Expecting charset %s/%d got %d\n",
47			$charsetInfo->charset, $charsetInfo->number, $tmp->charsetnr);
48	}
49	if ($tmp->length != $charsetInfo->max_length) {
50		printf("[006] Expecting length %d got %d\n",
51			$charsetInfo->max_length, $tmp->max_length);
52	}
53	if ($tmp->db != $db) {
54		printf("[007] Expecting database '%s' got '%s'\n",
55		  $db, $tmp->db);
56	}
57
58	var_dump($res->fetch_field());
59
60	$res->free_result();
61
62	if (NULL !== ($tmp = $res->fetch_field()))
63		printf("[007] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
64
65	$mysqli->close();
66	print "done!";
67?>
68--CLEAN--
69<?php
70	require_once("clean_table.inc");
71?>
72--EXPECTF--
73object(stdClass)#%d (13) {
74  ["name"]=>
75  string(2) "ID"
76  ["orgname"]=>
77  string(2) "id"
78  ["table"]=>
79  string(4) "TEST"
80  ["orgtable"]=>
81  string(4) "test"
82  ["def"]=>
83  string(0) ""
84  ["db"]=>
85  string(%d) "%s"
86  ["catalog"]=>
87  string(%d) "%s"
88  ["max_length"]=>
89  int(1)
90  ["length"]=>
91  int(11)
92  ["charsetnr"]=>
93  int(63)
94  ["flags"]=>
95  int(49155)
96  ["type"]=>
97  int(3)
98  ["decimals"]=>
99  int(0)
100}
101object(stdClass)#%d (13) {
102  ["name"]=>
103  string(5) "label"
104  ["orgname"]=>
105  string(5) "label"
106  ["table"]=>
107  string(4) "TEST"
108  ["orgtable"]=>
109  string(4) "test"
110  ["def"]=>
111  string(0) ""
112  ["db"]=>
113  string(%d) "%s"
114  ["catalog"]=>
115  string(%d) "%s"
116  ["max_length"]=>
117  int(%d)
118  ["length"]=>
119  int(%d)
120  ["charsetnr"]=>
121  int(%d)
122  ["flags"]=>
123  int(0)
124  ["type"]=>
125  int(254)
126  ["decimals"]=>
127  int(0)
128}
129bool(false)
130
131Warning: mysqli_result::fetch_field(): Couldn't fetch mysqli_result in %s on line %d
132done!
133