1--TEST--
2mysqli_stmt_get_result() - meta data, field info
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8
9if (!function_exists('mysqli_stmt_get_result'))
10	die('skip mysqli_stmt_get_result not available');
11?>
12--FILE--
13<?php
14	require('table.inc');
15
16	// Make sure that client, connection and result charsets are all the
17	// same. Not sure whether this is strictly necessary.
18	if (!mysqli_set_charset($link, 'utf8'))
19		printf("[%d] %s\n", mysqli_errno($link), mysqli_errno($link));
20
21	$charsetInfo = mysqli_get_charset($link);
22
23	if (!($stmt = mysqli_stmt_init($link)) ||
24		!mysqli_stmt_prepare($stmt, "SELECT id, label, id + 1 as _id,  concat(label, '_') ___label FROM test ORDER BY id ASC LIMIT 3") ||
25		!mysqli_stmt_execute($stmt))
26		printf("[001] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
27
28	if (!is_object($res = mysqli_stmt_get_result($stmt)) || 'mysqli_result' != get_class($res)) {
29		printf("[002] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
30			gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
31	}
32
33	if (!is_object($res_meta = mysqli_stmt_result_metadata($stmt)) ||
34		'mysqli_result' != get_class($res_meta)) {
35		printf("[003] Expecting object/mysqli_result got %s/%s, [%d] %s\n",
36			gettype($res), $res, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
37	}
38
39	$i = 0;
40	while ($field = $res->fetch_field()) {
41		var_dump($field);
42		$i++;
43		if (2 == $i) {
44			/*
45			Label column, result set charset.
46			All of the following columns are "too hot" - too server dependent
47			*/
48			if ($field->charsetnr != $charsetInfo->number) {
49				printf("[004] Expecting charset %s/%d got %d\n",
50					$charsetInfo->charset,
51					$charsetInfo->number, $field->charsetnr);
52			}
53			if ($field->length != $charsetInfo->max_length) {
54				printf("[005] Expecting length %d got %d\n",
55					$charsetInfo->max_length, $field->max_length);
56			}
57		}
58	}
59
60	mysqli_stmt_close($stmt);
61	mysqli_close($link);
62	print "done!";
63?>
64--CLEAN--
65<?php
66	require_once("clean_table.inc");
67?>
68--EXPECTF--
69object(stdClass)#%d (13) {
70  [%u|b%"name"]=>
71  %unicode|string%(2) "id"
72  [%u|b%"orgname"]=>
73  %unicode|string%(2) "id"
74  [%u|b%"table"]=>
75  %unicode|string%(4) "test"
76  [%u|b%"orgtable"]=>
77  %unicode|string%(4) "test"
78  [%u|b%"def"]=>
79  %unicode|string%(0) ""
80  [%u|b%"db"]=>
81  %unicode|string%(%d) "%s"
82  [%u|b%"catalog"]=>
83  %unicode|string%(%d) "%s"
84  [%u|b%"max_length"]=>
85  int(0)
86  [%u|b%"length"]=>
87  int(11)
88  [%u|b%"charsetnr"]=>
89  int(63)
90  [%u|b%"flags"]=>
91  int(49155)
92  [%u|b%"type"]=>
93  int(3)
94  [%u|b%"decimals"]=>
95  int(0)
96}
97object(stdClass)#%d (13) {
98  [%u|b%"name"]=>
99  %unicode|string%(5) "label"
100  [%u|b%"orgname"]=>
101  %unicode|string%(5) "label"
102  [%u|b%"table"]=>
103  %unicode|string%(4) "test"
104  [%u|b%"orgtable"]=>
105  %unicode|string%(4) "test"
106  [%u|b%"def"]=>
107  %unicode|string%(0) ""
108  [%u|b%"db"]=>
109  %unicode|string%(%d) "%s"
110  [%u|b%"catalog"]=>
111  %unicode|string%(%d) "%s"
112  [%u|b%"max_length"]=>
113  int(%d)
114  [%u|b%"length"]=>
115  int(%d)
116  [%u|b%"charsetnr"]=>
117  int(%d)
118  [%u|b%"flags"]=>
119  int(0)
120  [%u|b%"type"]=>
121  int(254)
122  [%u|b%"decimals"]=>
123  int(0)
124}
125object(stdClass)#%d (13) {
126  [%u|b%"name"]=>
127  %unicode|string%(3) "_id"
128  [%u|b%"orgname"]=>
129  %unicode|string%(0) ""
130  [%u|b%"table"]=>
131  %unicode|string%(0) ""
132  [%u|b%"orgtable"]=>
133  %unicode|string%(0) ""
134  [%u|b%"def"]=>
135  %unicode|string%(0) ""
136  [%u|b%"db"]=>
137  %unicode|string%(0) ""
138  [%u|b%"catalog"]=>
139  %unicode|string%(%d) "%s"
140  [%u|b%"max_length"]=>
141  int(0)
142  [%u|b%"length"]=>
143  int(%d)
144  [%u|b%"charsetnr"]=>
145  int(63)
146  [%u|b%"flags"]=>
147  int(32897)
148  [%u|b%"type"]=>
149  int(8)
150  [%u|b%"decimals"]=>
151  int(0)
152}
153object(stdClass)#%d (13) {
154  [%u|b%"name"]=>
155  %unicode|string%(8) "___label"
156  [%u|b%"orgname"]=>
157  %unicode|string%(0) ""
158  [%u|b%"table"]=>
159  %unicode|string%(0) ""
160  [%u|b%"orgtable"]=>
161  %unicode|string%(0) ""
162  [%u|b%"def"]=>
163  %unicode|string%(0) ""
164  [%u|b%"db"]=>
165  %unicode|string%(0) ""
166  [%u|b%"catalog"]=>
167  %unicode|string%(%d) "%s"
168  [%u|b%"max_length"]=>
169  int(%d)
170  [%u|b%"length"]=>
171  int(%d)
172  [%u|b%"charsetnr"]=>
173  int(%d)
174  [%u|b%"flags"]=>
175  int(0)
176  [%u|b%"type"]=>
177  int(253)
178  [%u|b%"decimals"]=>
179  int(31)
180}
181done!
182