mysqli_kill
mysqli->kill()
(PHP 5)
mysqli->kill() — サーバに MySQL スレッドの停止を問い合わせる
説明
手続き型:
bool mysqli_kill
( mysqli $link
, int $processid
)
オブジェクト指向型(メソッド)
mysqli
bool kill
( int $processid
)
この関数は、processid で指定した MySQL スレッドの停止をサーバに問い合わせます。この値は、 mysqli_thread_id() 関数で取得したものである 必要があります。
実行中のクエリを停止するには、SQL コマンド KILL QUERY processid を使用する必要があります。
返り値
成功した場合に TRUE を、失敗した場合に FALSE を返します。
例
Example#1 オブジェクト指向型
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* スレッド ID を取得します */
$thread_id = $mysqli->thread_id;
/* 接続を終了します */
$mysqli->kill($thread_id);
/* これはエラーとなります */
if (!$mysqli->query("CREATE TABLE myCity LIKE City")) {
printf("Error: %s\n", $mysqli->error);
exit;
}
/* 接続を閉じます */
$mysqli->close();
?>
Example#2 手続き型
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* スレッド ID を取得します */
$thread_id = mysqli_thread_id($link);
/* 接続を終了します */
mysqli_kill($link, $thread_id);
/* これはエラーとなります */
if (!mysqli_query($link, "CREATE TABLE myCity LIKE City")) {
printf("Error: %s\n", mysqli_error($link));
exit;
}
/* 接続を閉じます */
mysqli_close($link);
?>
上の例の出力は以下となります。
Error: MySQL server has gone away