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($res), $res);
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    $tmp = mysqli_fetch_fields($res);
49
50    if (empty($tmp[0]) || empty($tmp[1]) || $tmp[0] != $field0_direct) {
51        printf("[012] mysqli_fetch_fields() return value is suspicious\n");
52        var_dump($tmp);
53    }
54
55    if (!mysqli_field_seek($res, 1))
56        printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57
58    if (!is_object($field1_direct = mysqli_fetch_field_direct($res, 1)))
59        printf("[014] Expecting object, got %s/%s, [%d] %s\n",
60            gettype($field1_direct), $field1_direct, mysqli_errno($link), mysqli_error($link));
61
62    if ($tmp[1] != $field1_direct) {
63        printf("[015] mysqli_fetch_field_direct() differs from mysqli_fetch_fields()\n");
64        var_dump($field1_direct);
65        var_dump($tmp);
66    }
67
68    if (1 !== ($tmp = mysqli_field_tell($res)))
69        printf("[016] Expecting int/1, got %s/%s, [%d] %s\n",
70            gettype($tmp), $tmp, mysqli_errno($link), mysqli_error($link));
71
72    mysqli_free_result($res);
73    mysqli_stmt_close($stmt);
74
75    try {
76        mysqli_stmt_result_metadata($stmt);
77    } catch (Error $exception) {
78        echo $exception->getMessage() . "\n";
79    }
80
81    mysqli_close($link);
82    print "done!";
83?>
84--CLEAN--
85<?php
86    require_once 'clean_table.inc';
87?>
88--EXPECTF--
89mysqli_stmt object is not fully initialized
90object(stdClass)#%d (13) {
91  ["name"]=>
92  string(2) "id"
93  ["orgname"]=>
94  string(2) "id"
95  ["table"]=>
96  string(4) "test"
97  ["orgtable"]=>
98  string(4) "test"
99  ["def"]=>
100  string(0) ""
101  ["db"]=>
102  string(%d) "%s"
103  ["catalog"]=>
104  string(%d) "%s"
105  ["max_length"]=>
106  int(0)
107  ["length"]=>
108  int(11)
109  ["charsetnr"]=>
110  int(63)
111  ["flags"]=>
112  int(49155)
113  ["type"]=>
114  int(3)
115  ["decimals"]=>
116  int(0)
117}
118mysqli_stmt object is already closed
119done!
120