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