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