1--TEST--
2mysqli_stmt_result_metadata()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11    require_once("connect.inc");
12
13    require('table.inc');
14
15    if (!$stmt = mysqli_stmt_init($link))
16        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
17
18    try {
19        mysqli_stmt_result_metadata($stmt);
20    } catch (Error $exception) {
21        echo $exception->getMessage() . "\n";
22    }
23
24    if (!mysqli_stmt_prepare($stmt, "SELECT id, label FROM test"))
25        printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
26
27    if (!is_object(($res = mysqli_stmt_result_metadata($stmt))))
28        printf("[006] Expecting object, got %s/%s\n", gettype($tmp), $tmp);
29
30    if (2 !== ($tmp = mysqli_num_fields($res)))
31        printf("[007] Expecting int/2, got %s/%s, [%d] %s\n",
32            gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
33
34    if (!is_object($field0_fetch = mysqli_fetch_field($res)))
35        printf("[008] Expecting object, got %s/%s, [%d] %s\n",
36            gettype($field0_fetch), $field0_fetch, mysqli_errno($link), mysqli_error($link));
37
38    if (!is_object($field0_direct = mysqli_fetch_field_direct($res, 0)))
39        printf("[009] Expecting object, got %s/%s, [%d] %s\n",
40            gettype($field0_direct), $field0_direct, mysqli_errno($link), mysqli_error($link));
41
42    if ($field0_fetch != $field0_direct) {
43        printf("[010] mysqli_fetch_field() differs from mysqli_fetch_field_direct()\n");
44        var_dump($field0_fetch);
45        var_dump($field0_direct);
46    }
47
48    var_dump($field0_fetch);
49
50    if (!is_array($tmp = mysqli_fetch_fields($res)))
51        printf("[011] Expecting array, got %s/%s, [%d] %s\n",
52            gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
53
54    if (empty($tmp[0]) || empty($tmp[1]) || $tmp[0] != $field0_direct) {
55        printf("[012] mysqli_fetch_fields() return value is suspicious\n");
56        var_dump($tmp);
57    }
58
59    if (!mysqli_field_seek($res, 1))
60        printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
61
62    if (!is_object($field1_direct = mysqli_fetch_field_direct($res, 1)))
63        printf("[014] Expecting object, got %s/%s, [%d] %s\n",
64            gettype($field1_direct), $field1_direct, mysqli_errno($link), mysqli_error($link));
65
66    if ($tmp[1] != $field1_direct) {
67        printf("[015] mysqli_fetch_field_direct() differs from mysqli_fetch_fields()\n");
68        var_dump($field1_direct);
69        var_dump($tmp);
70    }
71
72    if (1 !== ($tmp = mysqli_field_tell($res)))
73        printf("[016] Expecting int/1, got %s/%s, [%d] %s\n",
74            gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
75
76    mysqli_free_result($res);
77    mysqli_stmt_close($stmt);
78
79    try {
80        mysqli_stmt_result_metadata($stmt);
81    } catch (Error $exception) {
82        echo $exception->getMessage() . "\n";
83    }
84
85    mysqli_close($link);
86    print "done!";
87?>
88--CLEAN--
89<?php
90    require_once("clean_table.inc");
91?>
92--EXPECTF--
93mysqli_stmt object is not fully initialized
94object(stdClass)#%d (13) {
95  ["name"]=>
96  string(2) "id"
97  ["orgname"]=>
98  string(2) "id"
99  ["table"]=>
100  string(4) "test"
101  ["orgtable"]=>
102  string(4) "test"
103  ["def"]=>
104  string(0) ""
105  ["db"]=>
106  string(%d) "%s"
107  ["catalog"]=>
108  string(%d) "%s"
109  ["max_length"]=>
110  int(0)
111  ["length"]=>
112  int(11)
113  ["charsetnr"]=>
114  int(63)
115  ["flags"]=>
116  int(49155)
117  ["type"]=>
118  int(3)
119  ["decimals"]=>
120  int(0)
121}
122mysqli_stmt object is already closed
123done!
124