PHP MySQL mysqli_thread_id() Function

Definition

The mysqli_thread_id() function returns the current connection thread ID. After we have the id we can kill the connection with the mysqli_kill() function.

Syntax

PHP MySQL mysqli_thread_id() Function has the following syntax.

mysqli_thread_id(connection);

Parameter

  • connection - Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init()

Return

Returns the Thread ID for the current connection.

Example 1

Returns the current connection thread ID


<?php//from www .jav  a  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();
    }
    $t_id=mysqli_thread_id($con);
    
    mysqli_kill($con,$t_id);
?>

The thread ID is changed each time we reconnect.

Example 2


<?php/*from w  w  w  .  jav a2 s . co  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("select * from 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