English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_kill() function allows the server to kill a MySQL thread
mysqli_kill()The function accepts the process ID as a parameter and prompts the MySQL server to terminate the specified thread.
mysqli_kill($con, $processid);
Serial Number | Parameters and Description |
---|---|
1 | con(must) This is an object representing the connection to the MySQL Server. |
2 | processid(Required) It is an integer value representing the process ID. |
Returns TRUE on success, or FALSE on failure.
This function was first introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstratemysqli_kill()Function Usage (Procedural Style)-
<?php //Establish Connection $con = mysqli_connect("localhost", "root", "password", "test"); $id = mysqli_thread_id($con); mysqli_kill($con, $id); $res = mysqli_query($con, "CREATE TABLE Sample (name VARCHAR(255))"); if($res){ print("Success....."); } print("Failed......"); } ?>
Output Result
Failed.....
In an object-oriented style, the syntax of this function is$con-> kill();。Here is an example of this function in an object-oriented style;
<?php //Establish Connection $con = new mysqli("localhost", "root", "password", "test"); $id = $con->thread_id; $con->kill($id); $res = mysqli_query($con, "CREATE TABLE Sample (name VARCHAR(255))"); if($res){ print("Success....."); } print("Failed......"); } ?>
Output Result
Failed.....
Return the current connection's thread ID and then kill the connection:
<?php $connection_mysql = mysqli_connect("localhost", "root", "password", "mydb"); if (mysqli_connect_errno($connection_mysql)){ echo "Connection to MySql failed: " . mysqli_connect_error(); } // Get Thread ID $t_id = mysqli_thread_id($connection_mysql); // Kill Thread $res = mysqli_kill($connection_mysql, $t_id); if($res){ print("Thread terminated successfully......"); } Thread terminated successfully...... ?>
Output Result
Thread terminated successfully......