PHP mysqli_thread_safe() 函式



定義和用法

mysqli_thread_safe() 函式用於確定底層客戶端庫是否支援執行緒安全。

語法

mysqli_thread_safe(void);

引數

此函式不接受任何引數。

返回值

此函式返回一個布林值,如果底層客戶端庫是執行緒安全的,則為 TRUE;否則為 FALSE

PHP 版本

此函式首次在 PHP 5 版本中引入,並在所有後續版本中均有效。

示例

以下示例演示了 mysqli_thread_safe() 函式的用法(過程式風格)−

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

這將產生以下結果 −

Is thread safe

示例

在面向物件風格中,此函式的語法為 $con->thread_id;以下是此函式在面向物件風格中的示例 −

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

這將產生以下結果 −

Is thread safe

示例

<?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
廣告