mysqli::$thread_id
(PHP 5, PHP 7, PHP 8)
mysqli::$thread_id -- mysqli_thread_id - 현재 연결에 대한 스레드 ID를 반환합니다.
설명
객체 지향 스타일
int $mysqli->thread_id;
절차적 스타일
mysqli_thread_id(mysqli $mysql
): int
mysqli_thread_id() 함수는 mysqli_kill() 함수를 사용하여 종료될 수 있는 현재 연결에 대한 스레드 ID를 반환합니다. 연결이 끊어지고 mysqli_ping()으로 다시 연결하면 스레드 ID는 other가 됩니다. 따라서 필요할 때만 스레드 ID를 가져와야 합니다.
메모:
스레드 ID는 연결별로 할당됩니다. 따라서 연결이 끊어졌다가 다시 설정되면 새 스레드 ID가 할당됩니다.
실행 중인 쿼리를 종료하려면 SQL 명령 KILL QUERY processid
를 사용할 수 있습니다.
매개변수
mysql
- 절차적 스타일 전용: mysqli_connect() 또는 mysqli_init()에 의해 반환된 mysqli 객체
반환 값
현재 연결의 스레드 ID를 반환합니다.
Examples
예제 #1 $mysqli->thread_id 예제
객체 지향 스타일
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* determine our thread id */
$thread_id = $mysqli->thread_id;
/* Kill connection */
$mysqli->kill($thread_id);
/* This should produce an error */
if (!$mysqli->query("CREATE TABLE myCity LIKE City")) {
printf("Error: %s\n", $mysqli->error);
exit;
}
/* close connection */
$mysqli->close();
?>
절차적 스타일
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* determine our thread id */
$thread_id = mysqli_thread_id($link);
/* Kill connection */
mysqli_kill($link, $thread_id);
/* This should produce an error */
if (!mysqli_query($link, "CREATE TABLE myCity LIKE City")) {
printf("Error: %s\n", mysqli_error($link));
exit;
}
/* close connection */
mysqli_close($link);
?>
위의 예는 다음을 출력합니다.
Error: MySQL server has gone away
기타
- mysqli_kill() - MySQL 스레드를 종료하도록 서버에 요청