English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP mysqli_thread_safe() Function Usage and Example

PHP MySQLi Reference Manual

The mysqli_thread_safe() function returns whether it is thread-safe

Definition and Usage

mysqli_thread_safe()This function is used to inform whether the database client library is compiled as thread-safe.

Syntax

mysqli_thread_safe(void);

Parameters

This function does not accept any parameters.

Return Value

If the client library is thread-safe, this function returns a boolean value that isTRUE,otherwiseFALSE.

PHP Version

This function was first introduced in PHP version5introduced and can be used in all higher versions.

Online Example

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

Online Example

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

Online Example

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);
   }
?>

PHP MySQLi Reference Manual