xref: /PHP-8.2/ext/mysqli/tests/mysqli_kill.phpt (revision 62d393b1)
1--TEST--
2mysqli_kill()
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    try {
16        mysqli_kill($link, 0);
17    } catch (\ValueError $e) {
18        echo $e->getMessage() . \PHP_EOL;
19    }
20
21    if (!$thread_id = mysqli_thread_id($link))
22        printf("[004] Cannot determine thread id, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
23
24    $tmp = mysqli_kill($link, $thread_id);
25    if (!is_bool($tmp))
26        printf("[005] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp);
27
28    if ($res = mysqli_query($link, "SELECT id FROM test LIMIT 1"))
29        pintf("[006] Expecting boolean/false, got %s/%s\n", gettype($res), $res);
30
31    var_dump($error = mysqli_error($link));
32    if (!is_string($error) || ('' === $error))
33        printf("[007] Expecting string/any non empty, got %s/%s\n", gettype($error), $error);
34    var_dump($res);
35    var_dump($link);
36    if ($link->info != 'Records: 6  Duplicates: 0  Warnings: 0') {
37        printf("[008] mysqlnd used to be more verbose and used to support SELECT\n");
38    }
39
40    mysqli_close($link);
41
42    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
43        printf("[010] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
44
45    try {
46        mysqli_kill($link, -1);
47    } catch (\ValueError $e) {
48        echo $e->getMessage() . \PHP_EOL;
49    }
50    if ((!$res = mysqli_query($link, "SELECT id FROM test LIMIT 1")) ||
51        (!$tmp = mysqli_fetch_assoc($res))) {
52        printf("[011] Connection should not be gone, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
53    }
54    var_dump($tmp);
55    mysqli_free_result($res);
56    mysqli_close($link);
57
58    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
59        printf("[012] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
60
61    mysqli_change_user($link, "This might work if you accept anonymous users in your setup", "password", $db);
62    try {
63        mysqli_kill($link, -1);
64    } catch (\ValueError $e) {
65        echo $e->getMessage() . \PHP_EOL;
66    }
67
68    mysqli_close($link);
69
70    print "done!";
71?>
72--CLEAN--
73<?php
74    require_once("clean_table.inc");
75?>
76--EXPECTF--
77mysqli_kill(): Argument #2 ($process_id) must be greater than 0
78string(%d) "%s"
79bool(false)
80object(mysqli)#%d (%d) {
81  ["affected_rows"]=>
82  int(-1)
83  ["client_info"]=>
84  string(%d) "%s"
85  ["client_version"]=>
86  int(%d)
87  ["connect_errno"]=>
88  int(0)
89  ["connect_error"]=>
90  NULL
91  ["errno"]=>
92  int(%d)
93  ["error"]=>
94  string(%d) "%s"
95  ["error_list"]=>
96  array(1) {
97    [0]=>
98    array(3) {
99      ["errno"]=>
100      int(%d)
101      ["sqlstate"]=>
102      string(5) "%s"
103      ["error"]=>
104      string(%d) "%s"
105    }
106  }
107  ["field_count"]=>
108  int(0)
109  ["host_info"]=>
110  string(%d) "%s"
111  ["info"]=>
112  %s
113  ["insert_id"]=>
114  int(0)
115  ["server_info"]=>
116  string(%d) "%s"
117  ["server_version"]=>
118  int(%d)
119  ["sqlstate"]=>
120  string(5) "HY000"
121  ["protocol_version"]=>
122  int(10)
123  ["thread_id"]=>
124  int(%d)
125  ["warning_count"]=>
126  int(0)
127}
128mysqli_kill(): Argument #2 ($process_id) must be greater than 0
129array(1) {
130  ["id"]=>
131  string(1) "1"
132}
133mysqli_kill(): Argument #2 ($process_id) must be greater than 0
134done!
135