The mysqli_kill() function asks the server to kill a MySQL thread specified by the processid parameter.
PHP mysqli_kill() Function has the following syntax.
Object oriented style
bool mysqli::kill ( int $processid )
Procedural style
bool mysqli_kill ( mysqli $link , int $processid )
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection to use |
processid | Required. | The thread ID returned from mysqli_thread_id() |
It returns TRUE on success and FALSE on failure.
The following code gets the thread ID for the current connection, then kills the connection.
<?php/*from ww w . java 2 s .c o m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Get thread id
$t_id=mysqli_thread_id($con);
// Kill connection
mysqli_kill($con,$t_id);
?>
<?php//from ww w .j a v a 2 s. c om
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$thread_id = $mysqli->thread_id;
$mysqli->kill($thread_id);
// This should produce an error
if (!$mysqli->query("CREATE TABLE myEmp LIKE emp")) {
printf("Error: %s\n", $mysqli->error);
exit;
}
$mysqli->close();
?>