PHP mysqli_kill() 函式



定義和用法

mysqli_kill() 函式接受一個程序 ID 作為引數,並提示 MySQL 伺服器終止指定的執行緒。

語法

mysqli_kill($con, $processid);

引數

序號 引數及描述
1

con(必填)

這是一個代表與 MySQL 伺服器連線的物件。

2

processid(必填)

這是一個代表程序 ID 的整數值。

返回值

此函式返回布林值,如果操作成功則為 true,失敗則為 false

PHP 版本

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

示例

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

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

   $id = mysqli_thread_id($con);

   mysqli_kill($con, $id);

   $res = mysqli_query($con, "CREATE TABLE Sample (name VARCHAR(255))");

   if($res){
      print("Successful.....");
   }else{
      print("Failed......");
   }
?>

這將產生以下結果 −

Failed.....

示例

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

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

   $id = $con->thread_id;

   $con->kill($id);

   $res = mysqli_query($con, "CREATE TABLE Sample (name VARCHAR(255))");

   if($res){
      print("Successful.....");
   }else{
      print("Failed......");
   }
?>

這將產生以下結果 −

Failed.....

示例

<?php
   $connection_mysql=mysqli_connect("localhost","root","password","mydb");
   
   if (mysqli_connect_errno($connection_mysql)){
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }
   
   $t_id = mysqli_thread_id($connection_mysql);
   
   $res = mysqli_kill($connection_mysql,$t_id);
   
   if($res){
	   print("Thread terminated successfully......");
   }
   Thread terminated successfully......
?>

這將產生以下結果 −

Thread terminated successfully......
php_function_reference.htm
廣告