mysqli thread_safe() Method
The mysqli::thread_safe() / mysqli_thread_safe() function tells whether the client library is compiled as thread-safe.
Syntax
//Object-oriented style public mysqli::thread_safe() //Procedural style mysqli_thread_safe()
Parameters
No parameter is required.
Return Value
Returns true if the client library is thread-safe, otherwise false.
Example: Object-oriented style
The example below shows the usage of mysqli::thread_safe() method.
<?php //establishing connection to the database $mysqli = new mysqli("localhost", "user", "password", "database"); if ($mysqli->connect_errno) { echo "Failed to connect to MySQL: ". $mysqli->connect_error; exit(); } //checking thread safe or not $result = $mysqli->thread_safe(); if($result){ print("Thread safety is given."); }else{ print("Thread safety is not given."); } //closing the connection $mysqli->close(); ?>
The output of the above code will be similar to:
Thread safety is given.
Example: Procedural style
The example below shows the usage of mysqli_thread_safe() function.
<?php //establishing connection to the database $mysqli = mysqli_connect("localhost", "user", "password", "database"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: ". mysqli_connect_error(); exit(); } //checking thread safe or not $result = mysqli_thread_safe(); if($result){ print("Thread safety is given."); }else{ print("Thread safety is not given."); } //closing the connection mysqli_close($mysqli); ?>
The output of the above code will be similar to:
Thread safety is given.
❮ MySQLi Functions Reference