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.
PHP MySQL mysqli_thread_id() Function has the following syntax.
mysqli_thread_id(connection);
Returns the Thread ID for the current connection.
Returns the current connection thread ID
<?php
$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.
<?php// www . ja v a2 s .c om
$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();
?>