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  [%u|b%"name"]=>
75  %unicode|string%(2) "ID"
76  [%u|b%"orgname"]=>
77  %unicode|string%(2) "id"
78  [%u|b%"table"]=>
79  %unicode|string%(4) "TEST"
80  [%u|b%"orgtable"]=>
81  %unicode|string%(4) "test"
82  [%u|b%"def"]=>
83  %unicode|string%(0) ""
84  [%u|b%"db"]=>
85  %unicode|string%(%d) "%s"
86  [%u|b%"catalog"]=>
87  %unicode|string%(%d) "%s"
88  [%u|b%"max_length"]=>
89  int(1)
90  [%u|b%"length"]=>
91  int(11)
92  [%u|b%"charsetnr"]=>
93  int(63)
94  [%u|b%"flags"]=>
95  int(49155)
96  [%u|b%"type"]=>
97  int(3)
98  [%u|b%"decimals"]=>
99  int(0)
100}
101object(stdClass)#%d (13) {
102  [%u|b%"name"]=>
103  %unicode|string%(5) "label"
104  [%u|b%"orgname"]=>
105  %unicode|string%(5) "label"
106  [%u|b%"table"]=>
107  %unicode|string%(4) "TEST"
108  [%u|b%"orgtable"]=>
109  %unicode|string%(4) "test"
110  [%u|b%"def"]=>
111  %unicode|string%(0) ""
112  [%u|b%"db"]=>
113  %unicode|string%(%d) "%s"
114  [%u|b%"catalog"]=>
115  %unicode|string%(%d) "%s"
116  [%u|b%"max_length"]=>
117  int(%d)
118  [%u|b%"length"]=>
119  int(%d)
120  [%u|b%"charsetnr"]=>
121  int(%d)
122  [%u|b%"flags"]=>
123  int(0)
124  [%u|b%"type"]=>
125  int(254)
126  [%u|b%"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