1--TEST--
2mysqli_stmt_result_metadata()
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	if (!is_null($tmp = @mysqli_stmt_result_metadata()))
17		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
18
19	if (!is_null($tmp = @mysqli_stmt_result_metadata($link)))
20		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
21
22	require('table.inc');
23
24	if (!$stmt = mysqli_stmt_init($link))
25		printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
26
27	if (NULL !== ($tmp = mysqli_stmt_result_metadata($stmt)))
28		printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
29
30	if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test"))
31		printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
32
33	if (!is_object(($res = mysqli_stmt_result_metadata($stmt))))
34		printf("[006] Expecting object, got %s/%s\n", gettype($tmp), $tmp);
35
36	if (2 !== ($tmp = mysqli_num_fields($res)))
37		printf("[007] Expecting int/2, got %s/%s, [%d] %s\n",
38			gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
39
40	if (!is_object($field0_fetch = mysqli_fetch_field($res)))
41		printf("[008] Expecting object, got %s/%s, [%d] %s\n",
42			gettype($field0_fetch), $field0_fetch, mysqli_errno($link), mysqli_error($link));
43
44	if (!is_object($field0_direct = mysqli_fetch_field_direct($res, 0)))
45		printf("[009] Expecting object, got %s/%s, [%d] %s\n",
46			gettype($field0_direct), $field0_direct, mysqli_errno($link), mysqli_error($link));
47
48	if ($field0_fetch != $field0_direct) {
49		printf("[010] mysqli_fetch_field() differs from mysqli_fetch_field_direct()\n");
50		var_dump($field0_fetch);
51		var_dump($field0_direct);
52	}
53
54	var_dump($field0_fetch);
55
56	if (!is_array($tmp = mysqli_fetch_fields($res)))
57		printf("[011] Expecting array, got %s/%s, [%d] %s\n",
58			gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
59
60	if (empty($tmp[0]) || empty($tmp[1]) || $tmp[0] != $field0_direct) {
61		printf("[012] mysqli_fetch_fields() return value is suspicious\n");
62		var_dump($tmp);
63	}
64
65	if (!mysqli_field_seek($res, 1))
66		printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
67
68	if (!is_object($field1_direct = mysqli_fetch_field_direct($res, 1)))
69		printf("[014] Expecting object, got %s/%s, [%d] %s\n",
70			gettype($field1_direct), $field1_direct, mysqli_errno($link), mysqli_error($link));
71
72	if ($tmp[1] != $field1_direct) {
73		printf("[015] mysqli_fetch_field_direct() differs from mysqli_fetch_fields()\n");
74		var_dump($field1_direct);
75		var_dump($tmp);
76	}
77
78	if (1 !== ($tmp = mysqli_field_tell($res)))
79		printf("[016] Expecting int/1, got %s/%s, [%d] %s\n",
80			gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
81
82	mysqli_free_result($res);
83	mysqli_stmt_close($stmt);
84
85	if (NULL !== ($tmp = mysqli_stmt_result_metadata($stmt)))
86		printf("[017] Expecting NULL, got %s/%s\n");
87
88	/* Check that the function alias exists. It's a deprecated function,
89	but we have not announce the removal so far, therefore we need to check for it */
90	if (!is_null($tmp = @mysqli_stmt_result_metadata()))
91		printf("[018] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
92
93	mysqli_close($link);
94	print "done!";
95?>
96--CLEAN--
97<?php
98	require_once("clean_table.inc");
99?>
100--EXPECTF--
101
102Warning: mysqli_stmt_result_metadata(): invalid object or resource mysqli_stmt
103 in %s on line %d
104object(stdClass)#5 (13) {
105  [%u|b%"name"]=>
106  %unicode|string%(2) "id"
107  [%u|b%"orgname"]=>
108  %unicode|string%(2) "id"
109  [%u|b%"table"]=>
110  %unicode|string%(4) "test"
111  [%u|b%"orgtable"]=>
112  %unicode|string%(4) "test"
113  [%u|b%"def"]=>
114  %unicode|string%(0) ""
115  [%u|b%"db"]=>
116  %unicode|string%(%d) "%s"
117  [%u|b%"catalog"]=>
118  %unicode|string%(%d) "%s"
119  [%u|b%"max_length"]=>
120  int(0)
121  [%u|b%"length"]=>
122  int(11)
123  [%u|b%"charsetnr"]=>
124  int(63)
125  [%u|b%"flags"]=>
126  int(49155)
127  [%u|b%"type"]=>
128  int(3)
129  [%u|b%"decimals"]=>
130  int(0)
131}
132
133Warning: mysqli_stmt_result_metadata(): Couldn't fetch mysqli_stmt in %s on line %d
134done!