English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP mysqli_kill() Function Usage and Example

PHP MySQLi Reference Manual

The mysqli_kill() function allows the server to kill a MySQL thread

Definition and Usage

mysqli_kill()The function accepts the process ID as a parameter and prompts the MySQL server to terminate the specified thread.

Syntax

mysqli_kill($con, $processid);

Parameter

Serial NumberParameters 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.

Return Value

 Returns TRUE on success, or FALSE on failure.

PHP Version

This function was first introduced in PHP version5introduced and can be used in all higher versions.

Online Example

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.....

Online Example

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.....

Online Example

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......

PHP MySQLi Reference Manual