English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Die Funktion mysqli_thread_id() gibt die aktuelle Thread-ID der Verbindung zurück
mysqli_thread_id()Die Funktion akzeptiert ein Verbindungsobjekt und gibt die Thread-ID der angegebenen Verbindung zurück.
mysqli_thread_id($con);
Reihennummer | Parameter und Beschreibung |
---|---|
1 | con (必需) Dies ist ein Objekt, das die Verbindung zum MySQL Server darstellt. |
Diese Funktion gibt einen Ganzzahlwert zurück, der die Thread-ID der aktuellen Verbindung darstellt.
This function was originally introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstratemysqli_thread_id()Usage of the function (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
In the object-oriented style, the syntax of 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", "test"); //Current thread ID $id = $con->thread_id; print("Current thread ID: " . $id); ?>
Output result
Current thread ID: 55
The following 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.....
In the object-oriented style, the syntax of this function is$con->kill();.The following 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 has been successfully terminated......"); } ?>
Output result
Thread has been successfully terminated......