mysqli::$thread_id
(mysqli_thread_id) Returns the thread ID of the current connection
thread_id()
/ mysqli_thread_id()
function returns the thread ID of the current connection. You can then use the kill()
function to terminate the connection.
Note: If the connection is disconnected and reconnected, the thread ID will change. Therefore, get the thread ID only if needed.
Return the thread ID of the current connection and terminate the connection:
<?php $mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "my_db" ) ; if ( $mysqli -> connect_errno ) { echo "Failed to connect to MySQL: " . $mysqli -> connect_error ; exit ( ) ; } // Get the thread ID $thread_id = $mysqli -> thread_id ; // Terminate the connection $mysqli -> kill ( $thread_id ) ; ?>
Return the thread ID of the current connection and terminate the connection:
<?php $con = mysqli_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ; if ( mysqli_connect_errno ( ) ) { echo "Failed to connect to MySQL: " . mysqli_connect_error ( ) ; exit ; } // Get the thread ID $thread_id = mysqli_thread_id ( $con ) ; // Terminate the connection mysqli_kill ( $con , $thread_id ) ; ?>