English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_thread_safe() function returns whether it is thread-safe
mysqli_thread_safe()This function is used to inform whether the database client library is compiled as thread-safe.
mysqli_thread_safe(void);
This function does not accept any parameters.
If the client library is thread-safe, this function returns a boolean value that isTRUE,otherwiseFALSE.
This function was first introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstratemysqli_thread_safe()Function Usage (Procedural Style)-
<?php //Establish connection $con = mysqli_connect("localhost", "root", "password", "test"); //Thread Safety $res = mysqli_thread_safe(); if($res){ print("Thread-safe"); } print("Not thread-safe"); } ?>
Output Result
Thread-safe
In an object-oriented style, the syntax for 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", "mydb"); //Thread Safety $res = $con->thread_safe(); if($res){ print("Thread-safe"); } print("Not thread-safe"); } ?>
Output Result
Thread-safe
Return the thread ID of the current connection and then kill the connection:
<?php //Establish connection $con = mysqli_connect("localhost", "root", "password", "test"); if (mysqli_connect_errno($con)){ print("Failed to connect to MySQL: " . mysqli_connect_error()); } $res = mysqli_thread_safe(); //ID of the current thread $id = mysqli_thread_id($con); if($res){ mysqli_kill($con, $id); } ?>