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