xref: /PHP-7.2/ext/mysqli/tests/mysqli_kill.phpt (revision f1d7e3ca)
1--TEST--
2mysqli_kill()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	require_once("connect.inc");
12
13	$tmp    = NULL;
14	$link   = NULL;
15
16	if (!is_null($tmp = @mysqli_kill()))
17		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
18
19	if (!is_null($tmp = @mysqli_kill($link)))
20		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
21
22	require('table.inc');
23
24	// Zend will cast the NULL to 0
25	if (!is_bool($tmp = mysqli_kill($link, null)))
26		printf("[003] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp);
27
28	if (!$thread_id = mysqli_thread_id($link))
29		printf("[004] Cannot determine thread id, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
30
31	$tmp = mysqli_kill($link, $thread_id);
32	if (!is_bool($tmp))
33		printf("[005] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp);
34
35	if ($res = mysqli_query($link, "SELECT id FROM test LIMIT 1"))
36		pintf("[006] Expecting boolean/false, got %s/%s\n", gettype($res), $res);
37
38	var_dump($error = mysqli_error($link));
39	if (!is_string($error) || ('' === $error))
40		printf("[007] Expecting string/any non empty, got %s/%s\n", gettype($error), $error);
41	var_dump($res);
42	var_dump($link);
43	if ($IS_MYSQLND) {
44		if ($link->info != 'Records: 6  Duplicates: 0  Warnings: 0') {
45			printf("[008] mysqlnd used to be more verbose and used to support SELECT\n");
46		}
47		if ($link->stat != NULL) {
48			printf("[009] NULL expected because of error.\n");
49		}
50	} else {
51		if ($link->info != NULL) {
52			printf("[008] Time for wonders - libmysql has started to support SELECT, change test\n");
53		}
54	}
55
56	mysqli_close($link);
57
58	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
59		printf("[010] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
60
61	mysqli_kill($link, -1);
62	if ((!$res = mysqli_query($link, "SELECT id FROM test LIMIT 1")) ||
63		(!$tmp = mysqli_fetch_assoc($res))) {
64		printf("[011] Connection should not be gone, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
65	}
66	var_dump($tmp);
67	mysqli_free_result($res);
68	mysqli_close($link);
69
70	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
71		printf("[012] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
72
73	mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db);      mysqli_kill($link, -1);
74
75	mysqli_close($link);
76
77	print "done!";
78?>
79--CLEAN--
80<?php
81	require_once("clean_table.inc");
82?>
83--EXPECTF--
84Warning: mysqli_kill(): processid should have positive value in %s on line %d
85string(%d) "%s"
86bool(false)
87object(mysqli)#%d (%d) {
88  ["affected_rows"]=>
89  int(-1)
90  ["client_info"]=>
91  string(%d) "%s"
92  ["client_version"]=>
93  int(%d)
94  ["connect_errno"]=>
95  int(0)
96  ["connect_error"]=>
97  NULL
98  ["errno"]=>
99  int(2006)
100  ["error"]=>
101  string(%d) "%s"
102  ["error_list"]=>
103  array(1) {
104    [0]=>
105    array(3) {
106      ["errno"]=>
107      int(2006)
108      ["sqlstate"]=>
109      string(5) "%s"
110      ["error"]=>
111      string(%d) "%s"
112    }
113  }
114  ["field_count"]=>
115  int(0)
116  ["host_info"]=>
117  string(%d) "%s"
118  ["info"]=>
119  %s
120  ["insert_id"]=>
121  int(0)
122  ["server_info"]=>
123  string(%d) "%s"
124  ["server_version"]=>
125  int(%d)
126  ["stat"]=>
127  %s
128  ["sqlstate"]=>
129  string(5) "HY000"
130  ["protocol_version"]=>
131  int(10)
132  ["thread_id"]=>
133  int(%d)
134  ["warning_count"]=>
135  int(0)
136}
137
138Warning: mysqli_kill(): processid should have positive value in %s on line %d
139array(1) {
140  ["id"]=>
141  string(1) "1"
142}
143
144Warning: mysqli_kill(): processid should have positive value in %s on line %d
145done!
146