PHP mysqli_kill() Function

Definition

The mysqli_kill() function asks the server to kill a MySQL thread specified by the processid parameter.

Syntax

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

ParameterIs RequiredDescription
connectionRequired.MySQL connection to use
processidRequired.The thread ID returned from mysqli_thread_id()

Return

It returns TRUE on success and FALSE on failure.

Example

The following code gets the thread ID for the current connection, then kills the connection.


<?php/*from www.j a  va 2  s . co  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);
?>

Example 2


<?php//from   w w  w .j a v a 2s  .c  o  m
$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();
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions