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