定义和用法
这个mysqli_thread_id()函数接受一个连接对象并返回给定连接的线程 ID。
用法
mysqli_thread_id($con);
参数
| Sr.No | 参数及说明 | 
|---|---|
| 1 | 
 con(Mandatory) 这是一个表示与 MySQL 服务器的连接的对象。  | 
返回值
此函数返回一个整数值,表示当前连接的线程 ID。
PHP版本
这个函数最初是在 PHP 版本 5 中引入的,适用于所有后续版本。
示例
以下示例演示了 mysqli_thread_id() 函数的用法(程序风格) -
<?php
   //Creating the connection
   $con = mysqli_connect("localhost","root","password","test");
   //Id of the current thread
   $id = mysqli_thread_id($con);
   print("Current thread id:".$id);
?>
这将产生以下结果 -
Current thread id:55
示例
在面向对象的风格中,这个函数的语法是 $con-> thread_id;以下是面向对象样式 $minus 中此函数的示例;
<?php
   //Creating the connection
   $con = new mysqli("localhost","root","password","test");
   //Current thread id
   $id = $con->thread_id;
   print("Current thread id:".$id);
?>
这将产生以下结果 -
Current thread id:55
示例
下面是这个函数的另一个例子,它重试当前线程的 id 并杀死它 $minus;
<?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();以下是面向对象样式 $minus 中此函数的示例;
<?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_thread_id($connection_mysql,$t_id);
   
   if($res){
	   print("Thread terminated successfully......");
   }
?>
这将产生以下结果 -
Thread terminated successfully......
相关用法
- PHP mysqli_thread_safe()用法及代码示例
 - PHP mysqli_get_server_info()用法及代码示例
 - PHP mysqli_data_seek()用法及代码示例
 - PHP mysqli_insert_id()用法及代码示例
 - PHP mysqli_fetch_assoc()用法及代码示例
 - PHP mysqli_connect_error()用法及代码示例
 - PHP mysqli_fetch_all()用法及代码示例
 - PHP mysqli_next_result()用法及代码示例
 - PHP mysqli_stmt_affected_rows()用法及代码示例
 - PHP mysqli_begin_transaction()用法及代码示例
 - PHP mysqli_real_escape_string()用法及代码示例
 - PHP mysqli_fetch_lengths()用法及代码示例
 - PHP mysqli_character_set_name()用法及代码示例
 - PHP mysqli_free_result()用法及代码示例
 - PHP mysqli_fetch_row()用法及代码示例
 - PHP mysqli_debug()用法及代码示例
 - PHP mysqli_commit()用法及代码示例
 - PHP mysqli_fetch_field()用法及代码示例
 - PHP mysqli_kill()用法及代码示例
 - PHP mysqli_get_connection_stats()用法及代码示例
 
注:本文由纯净天空筛选整理自 PHP mysqli_thread_id() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
