summaryrefslogtreecommitdiff
path: root/ext/mysqli/tests/mysqli_get_connection_stats.phpt
blob: ba71cd649a4e79546d5165af51ab239520f0097f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
--TEST--
mysqli_get_connection_stats()
--SKIPIF--
<?PHP
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('skipifconnectfailure.inc');
if (!function_exists('mysqli_get_connection_stats')) {
	die("skip only available with mysqlnd");
}
?>
--FILE--
<?php
	$tmp = $link = null;
	if (!is_null($tmp = @mysqli_get_connection_stats()))
		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);

	if (!is_null($tmp = @mysqli_get_connection_stats($link)))
		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);

	include "connect.inc";
	include "table.inc";

	if (!is_array($info = mysqli_get_connection_stats($link)) || empty($info))
		printf("[003] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);

	if (!is_array($info2 = mysqli_get_client_stats()) || empty($info2))
		printf("[004] Expecting array/any_non_empty, got %s/%s\n", gettype($info2), $info2);

	foreach ($info as $k => &$v) {
		if (strpos($k, "mem_") === 0) {
			$v = 0;
		}
	}
	foreach ($info2 as $k => &$v) {
		if (strpos($k, "mem_") === 0) {
			$v = 0;
		}
	}

	if ($info !== $info2) {
		printf("[005] The hashes should be identical\n");
		var_dump($info);
		var_dump($info2);
	}

	mysqli_close($link);
	include "table.inc";

	if (!is_array($info = mysqli_get_connection_stats($link)) || empty($info))
		printf("[006] Expecting array/any_non_empty, got %s/%s\n", gettype($info), $info);

	if (!is_array($info2 = mysqli_get_client_stats()) || empty($info2))
		printf("[007] Expecting array/any_non_empty, got %s/%s\n", gettype($info2), $info2);

	// assuming the test is run in a plain-vanilla CLI environment
	if ($info === $info2) {
		printf("[008] The hashes should not be identical\n");
		var_dump($info);
		var_dump($info2);
	}

	print "done!";
?>
--EXPECTF--
done!