1--TEST--
2mysqli_stmt_get_result() - meta data, field info
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
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  ["name"]=>
71  string(2) "id"
72  ["orgname"]=>
73  string(2) "id"
74  ["table"]=>
75  string(4) "test"
76  ["orgtable"]=>
77  string(4) "test"
78  ["def"]=>
79  string(0) ""
80  ["db"]=>
81  string(%d) "%s"
82  ["catalog"]=>
83  string(%d) "%s"
84  ["max_length"]=>
85  int(0)
86  ["length"]=>
87  int(11)
88  ["charsetnr"]=>
89  int(63)
90  ["flags"]=>
91  int(49155)
92  ["type"]=>
93  int(3)
94  ["decimals"]=>
95  int(0)
96}
97object(stdClass)#%d (13) {
98  ["name"]=>
99  string(5) "label"
100  ["orgname"]=>
101  string(5) "label"
102  ["table"]=>
103  string(4) "test"
104  ["orgtable"]=>
105  string(4) "test"
106  ["def"]=>
107  string(0) ""
108  ["db"]=>
109  string(%d) "%s"
110  ["catalog"]=>
111  string(%d) "%s"
112  ["max_length"]=>
113  int(%d)
114  ["length"]=>
115  int(%d)
116  ["charsetnr"]=>
117  int(%d)
118  ["flags"]=>
119  int(0)
120  ["type"]=>
121  int(254)
122  ["decimals"]=>
123  int(0)
124}
125object(stdClass)#%d (13) {
126  ["name"]=>
127  string(3) "_id"
128  ["orgname"]=>
129  string(0) ""
130  ["table"]=>
131  string(0) ""
132  ["orgtable"]=>
133  string(0) ""
134  ["def"]=>
135  string(0) ""
136  ["db"]=>
137  string(0) ""
138  ["catalog"]=>
139  string(%d) "%s"
140  ["max_length"]=>
141  int(0)
142  ["length"]=>
143  int(%d)
144  ["charsetnr"]=>
145  int(63)
146  ["flags"]=>
147  int(32897)
148  ["type"]=>
149  int(8)
150  ["decimals"]=>
151  int(0)
152}
153object(stdClass)#%d (13) {
154  ["name"]=>
155  string(8) "___label"
156  ["orgname"]=>
157  string(0) ""
158  ["table"]=>
159  string(0) ""
160  ["orgtable"]=>
161  string(0) ""
162  ["def"]=>
163  string(0) ""
164  ["db"]=>
165  string(0) ""
166  ["catalog"]=>
167  string(%d) "%s"
168  ["max_length"]=>
169  int(%d)
170  ["length"]=>
171  int(%d)
172  ["charsetnr"]=>
173  int(%d)
174  ["flags"]=>
175  int(0)
176  ["type"]=>
177  int(253)
178  ["decimals"]=>
179  int(3%d)
180}
181done!
182