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

Tutoriais básicos de PHP

Tutoriais avançados de PHP

PHP & MySQL

Manual de referência PHP

Uso e exemplo da função PHP mysqli_thread_id()

PHP MySQLi Reference Manual

A função mysqli_thread_id() retorna o ID da thread da conexão atual

Definição e uso

mysqli_thread_id()A função aceita um objeto de conexão e retorna o ID da thread da conexão fornecida.

Sintaxe

mysqli_thread_id($con);

Parâmetro

Número de ordemParâmetros e descrição
1

con(obrigatório)

Este é um objeto que representa a conexão com o MySQL Server.

Retorno

Esta função retorna um valor inteiro que representa o ID da thread de conexão atual.

PHP version

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

Online example

The following examples demonstratemysqli_thread_id()Function usage (procedural style)-

<?php
   //Establish connection
   $con = mysqli_connect("localhost", "root", "password", "test");
   //Current thread ID
   $id = mysqli_thread_id($con);
   print("Current thread ID: " . $id);
?>

Output result

Current thread ID: 55

Online example

In the object-oriented style, the syntax of this function is$con->thread_id; Here is an example of this function in an object-oriented style;

<?php
   //Establish connection
   $con = new mysqli("localhost", "root", "password", "test");
   //Current thread ID
   $id = $con->thread_id;
   print("Current thread ID: " . $id);
?>

Output result

Current thread ID: 55

Online example

Here is another example of this function, returning the thread ID of the current connection, and then using the mysqli_kill() function to kill the connection:

<?php
   //Establish 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......");
   }
?>

Output result

Failed.....

Online example

In the object-oriented style, the syntax of this function is$con->kill();。Here is an example of this function in an object-oriented style;

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

Output result

Thread terminated successfully......

PHP MySQLi Reference Manual