English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_thread_id() function returns the current connection's thread ID
mysqli_thread_id()The function accepts a connection object and returns the thread ID of the given connection.
mysqli_thread_id($con);
Serial Number | Parameters and Description |
---|---|
1 | con(Required) This is an object representing a connection with the MySQL Server. |
This function returns an integer value that represents the thread ID of the current connection.
This function was initially introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstratemysqli_thread_id()Usage of the Function (Procedural Style)-
<?php //Establish Connection $con = mysqli_connect("localhost", "root", "password", "test"); //Current Thread ID $id = mysqli_thread_id($con); print("Current Thread ID: " . $id); ?>
Output Result
Current Thread ID: 55
In the object-oriented style, the syntax of this function is$con->thread_id; The following is an example of this function in an object-oriented style;
<?php //Establish Connection $con = new mysqli("localhost", "root", "password", "test"); //Current Thread ID $id = $con->thread_id; print("Current Thread ID: " . $id); ?>
Output Result
Current Thread ID: 55
The following is another example of this function, which returns the thread ID of the current connection and then uses the mysqli_kill() function to kill the connection:
<?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("Successful....."); } print("Failed......"); } ?>
Output Result
Failed.....
In the object-oriented style, the syntax of this function is$con->kill();。The following is an example of this function in an object-oriented style;
<?php $connection_mysql = mysqli_connect("localhost", "root", "password", "mydb"); if (mysqli_connect_errno($connection_mysql)){ echo "Connection to MySQL failed: " . mysqli_connect_error(); } $t_id = mysqli_thread_id($connection_mysql); $res = mysqli_thread_id($connection_mysql, $t_id); if($res){ print("Thread terminated successfully......"); } ?>
Output Result
Thread terminated successfully......