1--TEST--
2mysqli_get_connection_stats()
3--INI--
4mysqlnd.collect_statistics="1"
5mysqlnd.collect_memory_statistics="1"
6--SKIPIF--
7<?PHP
8require_once('skipif.inc');
9require_once('skipifemb.inc');
10require_once('skipifconnectfailure.inc');
11if (!function_exists('mysqli_get_connection_stats')) {
12    die("skip only available with mysqlnd");
13}
14?>
15--FILE--
16<?php
17    $tmp = $link = null;
18    if (!is_null($tmp = @mysqli_get_connection_stats()))
19        printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
20
21    if (!is_null($tmp = @mysqli_get_connection_stats($link)))
22        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
23
24    require("table.inc");
25
26    if (!is_array($info = mysqli_get_connection_stats($link)) || empty($info))
27        printf("[003] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);
28
29    if (!is_array($info2 = mysqli_get_client_stats()) || empty($info2))
30        printf("[004] Expecting array/any_non_empty, got %s/%s\n", gettype($info2), $info2);
31
32    foreach ($info as $k => &$v) {
33        if (strpos($k, "mem_") === 0) {
34            $v = 0;
35        }
36    }
37    foreach ($info2 as $k => &$v) {
38        if (strpos($k, "mem_") === 0) {
39            $v = 0;
40        }
41    }
42
43    if ($info !== $info2) {
44        printf("[005] The hashes should be identical except of the memory related fields\n");
45        var_dump($info);
46        var_dump($info2);
47    }
48
49    if (!is_array($info = $link->get_connection_stats()) || empty($info))
50        printf("[006] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);
51
52    foreach ($info as $k => &$v) {
53        if (strpos($k, "mem_") === 0) {
54            $v = 0;
55        }
56    }
57
58    if ($info !== $info2) {
59        printf("[007] The hashes should be identical except of the memory related fields\n");
60        var_dump($info);
61        var_dump($info2);
62    }
63
64    mysqli_close($link);
65    require("table.inc");
66
67    if (!is_array($info = mysqli_get_connection_stats($link)) || empty($info))
68        printf("[008] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);
69
70    if (!is_array($info2 = mysqli_get_client_stats()) || empty($info2))
71        printf("[009] Expecting array/any_non_empty, got %s/%s\n", gettype($info2), $info2);
72
73    // assuming the test is run in a plain-vanilla CLI environment
74    if ($info === $info2) {
75        printf("[010] The hashes should not be identical\n");
76        var_dump($info);
77        var_dump($info2);
78    }
79
80    print "done!";
81?>
82--CLEAN--
83<?php
84    require_once("clean_table.inc");
85?>
86--EXPECT--
87done!
88