PHP mysqli_thread_id()関数
例-オブジェクト指向スタイル
現在の接続のスレッドIDを返し、接続を切断します。
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Get thread id
$thread_id = $mysqli -> thread_id;
// Kill connection
$mysqli -> kill($thread_id);
?>
下部にある手続き型の例を見てください。
定義と使用法
thread_id()/ mysqli_thread_id()関数は、現在の接続のスレッドIDを返します。その後、 kill()関数を使用して接続を切断でき ます。
注:接続が切断されて再接続すると、スレッドIDが変更されます。したがって; 必要な場合にのみスレッドIDを取得します。
構文
オブジェクト指向スタイル:
$mysqli -> thread_id()
手続き型:
mysqli_thread_id(connection)
パラメータ値
Parameter | Description |
---|---|
connection | Required. Specifies the MySQL connection to use |
技術的な詳細
戻り値: | 現在の接続のスレッドIDを返します |
---|---|
PHPバージョン: | 5歳以上 |
例-手続き型
現在の接続のスレッドIDを返し、接続を切断します。
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit;
}
// Get thread id
$thread_id = mysqli_thread_id($con);
// Kill connection
mysqli_kill($con, $thread_id);
?>
❮PHPMySQLiリファレンス