PHP mysqli_kill() Function
Definition and Usage
The mysqli_kill() function accepts a process id as a parameter and prompts the MySQL server to kill the specified thread.
Syntax
mysqli_kill($con, $processid);
Parameters
| Sr.No | Parameter & Description |
|---|---|
| 1 |
con(Mandatory) This is an object representing a connection to MySQL Server. |
| 2 |
processid(Mandatory) It is an integer value representing the process id. |
Return Values
This function returns the boolean value which is true if the operation was successful and false incase of failure.
PHP Version
This function was first introduced in PHP Version 5 and works works in all the later versions.
Example
Following example demonstrates the usage of the mysqli_kill() function (in procedural style) −
<?php
//Creating the 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("Successful.....");
}else{
print("Failed......");
}
?>
This will produce following result −
Failed.....
Example
In object oriented style the syntax of this function is $con-> kill(); Following is the example of this function in object oriented style $minus;
<?php
//Creating the 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("Successful.....");
}else{
print("Failed......");
}
?>
This will produce following result −
Failed.....
Example
<?php
$connection_mysql=mysqli_connect("localhost","root","password","mydb");
if (mysqli_connect_errno($connection_mysql)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$t_id = mysqli_thread_id($connection_mysql);
$res = mysqli_kill($connection_mysql,$t_id);
if($res){
print("Thread terminated successfully......");
}
Thread terminated successfully......
?>
This will produce following result −
Thread terminated successfully......