PHP mysqli_thread_id() Function
Definition and Usage
The mysqli_thread_id() function accepts a connection object and returns the thread id of the given connection.
Syntax
mysqli_thread_id($con);
Parameters
| Sr.No | Parameter & Description |
|---|---|
| 1 |
con(Mandatory) This is an object representing a connection to MySQL Server. |
Return Values
This function returns an integer value representing the Thread id of the current connection.
PHP Version
This function was first introduced in PHP Version 5 and works works in all the later versions.
Example
Following example demonstrates the usage of the mysqli_thread_id() function (in procedural style) −
<?php
//Creating the connection
$con = mysqli_connect("localhost","root","password","test");
//Id of the current thread
$id = mysqli_thread_id($con);
print("Current thread id: ".$id);
?>
This will produce following result −
Current thread id: 55
Example
In object oriented style the syntax of this function is $con-> thread_id; Following is the example of this function in object oriented style $minus;
<?php
//Creating the connection
$con = new mysqli("localhost","root","password","test");
//Current thread id
$id = $con->thread_id;
print("Current thread id: ".$id);
?>
This will produce following result −
Current thread id: 55
Example
Following is another example of this function, it retries the id of current thread and kills it $minus;
<?php
//Creating the 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.....");
}else{
print("Failed......");
}
?>
This will produce following result −
Failed.....
Example
In object oriented style the syntax of this function is $con-> kill(); Following is the example of this function in object oriented style $minus;
<?php
$connection_mysql=mysqli_connect("localhost","root","password","mydb");
if (mysqli_connect_errno($connection_mysql)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$t_id = mysqli_thread_id($connection_mysql);
$res = mysqli_thread_id($connection_mysql,$t_id);
if($res){
print("Thread terminated successfully......");
}
?>
This will produce following result −
Thread terminated successfully......