• PHP Video Tutorials

PHP mysqli_thread_safe() Function



Definition and Usage

The mysqli_thread_safe() function is used to determines whether the underlying client library supports thread safety or not.

Syntax

mysqli_thread_safe(void);

Parameters

This function does not accept any parameters.

Return Values

This function returns an boolean value which is TRUE if the underlying client library is thread safe and, FALSE if not

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_safe() function (in procedural style) −

<?php
   //Creating the connection
   $con = mysqli_connect("localhost","root","password","test");

   //Thread safe or not
   $res = mysqli_thread_safe();

   if($res){
      print("Is thread safe");
   }else{
      print("Is not thread safe");
   }
?>

This will produce following result −

Is thread safe

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","mydb");

   //Thread safe or not
   $res = $con->thread_safe();

   if($res){
      print("Is thread safe");
   }else{
      print("Is not thread safe");
   }
?>

This will produce following result −

Is thread safe

Example

<?php
   //Creating the 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);
   }
?>
php_function_reference.htm
Advertisements