xref: /PHP-7.4/ext/mysqli/tests/047.phpt (revision e3e67b72)
1--TEST--
2mysqli_stmt_result_metadata
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("connect.inc");
11
12    /*** test mysqli_connect 127.0.0.1 ***/
13    $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
14
15    mysqli_select_db($link, $db);
16
17    mysqli_query($link, "DROP TABLE IF EXISTS test_affected");
18    mysqli_query($link, "CREATE TABLE test_affected (foo int, bar varchar(10) character set latin1) ENGINE=" . $engine);
19
20    mysqli_query($link, "INSERT INTO test_affected VALUES (1, 'Zak'),(2, 'Greant')");
21
22    $stmt = mysqli_prepare($link, "SELECT * FROM test_affected");
23    mysqli_stmt_execute($stmt);
24    $result = mysqli_stmt_result_metadata($stmt);
25
26    echo "\n=== fetch_fields ===\n";
27    var_dump(mysqli_fetch_fields($result));
28
29    echo "\n=== fetch_field_direct ===\n";
30    var_dump(mysqli_fetch_field_direct($result, 0));
31    var_dump(mysqli_fetch_field_direct($result, 1));
32
33    echo "\n=== fetch_field ===\n";
34    while ($field = mysqli_fetch_field($result)) {
35        var_dump($field);
36    }
37
38    print_r(mysqli_fetch_lengths($result));
39
40    mysqli_free_result($result);
41
42
43    mysqli_stmt_close($stmt);
44    mysqli_query($link, "DROP TABLE IF EXISTS test_affected");
45    mysqli_close($link);
46    print "done!";
47?>
48--CLEAN--
49<?php
50require_once("connect.inc");
51if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
52   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
53
54if (!mysqli_query($link, "DROP TABLE IF EXISTS test_affected"))
55    printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
56
57mysqli_close($link);
58?>
59--EXPECTF--
60=== fetch_fields ===
61array(2) {
62  [0]=>
63  object(stdClass)#5 (13) {
64    ["name"]=>
65    string(3) "foo"
66    ["orgname"]=>
67    string(3) "foo"
68    ["table"]=>
69    string(13) "test_affected"
70    ["orgtable"]=>
71    string(13) "test_affected"
72    ["def"]=>
73    string(0) ""
74    ["db"]=>
75    string(%d) "%s"
76    ["catalog"]=>
77    string(%d) "%s"
78    ["max_length"]=>
79    int(0)
80    ["length"]=>
81    int(%d)
82    ["charsetnr"]=>
83    int(%d)
84    ["flags"]=>
85    int(32768)
86    ["type"]=>
87    int(3)
88    ["decimals"]=>
89    int(0)
90  }
91  [1]=>
92  object(stdClass)#6 (13) {
93    ["name"]=>
94    string(3) "bar"
95    ["orgname"]=>
96    string(3) "bar"
97    ["table"]=>
98    string(13) "test_affected"
99    ["orgtable"]=>
100    string(13) "test_affected"
101    ["def"]=>
102    string(0) ""
103    ["db"]=>
104    string(%d) "%s"
105    ["catalog"]=>
106    string(%d) "%s"
107    ["max_length"]=>
108    int(0)
109    ["length"]=>
110    int(%d)
111    ["charsetnr"]=>
112    int(%d)
113    ["flags"]=>
114    int(0)
115    ["type"]=>
116    int(253)
117    ["decimals"]=>
118    int(0)
119  }
120}
121
122=== fetch_field_direct ===
123object(stdClass)#6 (13) {
124  ["name"]=>
125  string(3) "foo"
126  ["orgname"]=>
127  string(3) "foo"
128  ["table"]=>
129  string(13) "test_affected"
130  ["orgtable"]=>
131  string(13) "test_affected"
132  ["def"]=>
133  string(0) ""
134  ["db"]=>
135  string(%d) "%s"
136  ["catalog"]=>
137  string(%d) "%s"
138  ["max_length"]=>
139  int(0)
140  ["length"]=>
141  int(%d)
142  ["charsetnr"]=>
143  int(%d)
144  ["flags"]=>
145  int(32768)
146  ["type"]=>
147  int(3)
148  ["decimals"]=>
149  int(0)
150}
151object(stdClass)#6 (13) {
152  ["name"]=>
153  string(3) "bar"
154  ["orgname"]=>
155  string(3) "bar"
156  ["table"]=>
157  string(13) "test_affected"
158  ["orgtable"]=>
159  string(13) "test_affected"
160  ["def"]=>
161  string(0) ""
162  ["db"]=>
163  string(%d) "%s"
164  ["catalog"]=>
165  string(%d) "%s"
166  ["max_length"]=>
167  int(0)
168  ["length"]=>
169  int(%d)
170  ["charsetnr"]=>
171  int(%d)
172  ["flags"]=>
173  int(0)
174  ["type"]=>
175  int(253)
176  ["decimals"]=>
177  int(0)
178}
179
180=== fetch_field ===
181object(stdClass)#6 (13) {
182  ["name"]=>
183  string(3) "foo"
184  ["orgname"]=>
185  string(3) "foo"
186  ["table"]=>
187  string(13) "test_affected"
188  ["orgtable"]=>
189  string(13) "test_affected"
190  ["def"]=>
191  string(0) ""
192  ["db"]=>
193  string(%d) "%s"
194  ["catalog"]=>
195  string(%d) "%s"
196  ["max_length"]=>
197  int(0)
198  ["length"]=>
199  int(%d)
200  ["charsetnr"]=>
201  int(%d)
202  ["flags"]=>
203  int(32768)
204  ["type"]=>
205  int(3)
206  ["decimals"]=>
207  int(0)
208}
209object(stdClass)#5 (13) {
210  ["name"]=>
211  string(3) "bar"
212  ["orgname"]=>
213  string(3) "bar"
214  ["table"]=>
215  string(13) "test_affected"
216  ["orgtable"]=>
217  string(13) "test_affected"
218  ["def"]=>
219  string(0) ""
220  ["db"]=>
221  string(%d) "%s"
222  ["catalog"]=>
223  string(%d) "%s"
224  ["max_length"]=>
225  int(0)
226  ["length"]=>
227  int(%d)
228  ["charsetnr"]=>
229  int(%d)
230  ["flags"]=>
231  int(0)
232  ["type"]=>
233  int(253)
234  ["decimals"]=>
235  int(0)
236}
237done!
238