1--TEST--
2mysqli_num_fields()
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    function func_test_mysqli_num_fields($link, $query, $expected, $offset, $test_free = false) {
16
17        if (!($res = mysqli_query($link, $query))) {
18            printf("[%03d] [%d] %s\n", $offset, mysqli_errno($link), mysqli_error($link));
19            return;
20        }
21
22        if ($expected !== ($tmp = mysqli_num_fields($res)))
23            printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1,
24                gettype($expected), $expected,
25                gettype($tmp), $tmp);
26
27        mysqli_free_result($res);
28
29        try {
30            mysqli_num_fields($res);
31        } catch (Error $exception) {
32            echo $exception->getMessage() . "\n";
33        }
34    }
35
36    func_test_mysqli_num_fields($link, "SELECT 1 AS a", 1, 5);
37    func_test_mysqli_num_fields($link, "SELECT id, label FROM test", 2, 10);
38    func_test_mysqli_num_fields($link, "SELECT 1 AS a, NULL AS b, 'foo' AS c", 3, 15);
39    func_test_mysqli_num_fields($link, "SELECT id FROM test", 1, 20, true);
40
41    mysqli_close($link);
42
43    print "done!";
44?>
45--CLEAN--
46<?php
47    require_once("clean_table.inc");
48?>
49--EXPECT--
50mysqli_result object is already closed
51mysqli_result object is already closed
52mysqli_result object is already closed
53mysqli_result object is already closed
54done!
55