PHP MySQL mysqli_thread_id() Function
In this chapter you will learn:
- Definition for PHP MySQL mysqli_thread_id() Function
- Syntax for PHP MySQL mysqli_thread_id() Function
- Parameter for PHP MySQL mysqli_thread_id() Function
- Return for PHP MySQL mysqli_thread_id() Function
- Example - returns the current connection thread ID
- Example - Object oriented style
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 j a va 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 java2s. 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();
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_thread_safe() Function
- Syntax for PHP mysqli_thread_safe() Function
- Parameter for PHP mysqli_thread_safe() Function
- Return for PHP mysqli_thread_safe() Function
- Example - Is the client thread safe
Home » PHP Tutorial » PHP MySQLi Functions