CakeFest 2024: The Official CakePHP Conference

mysqli::kill

mysqli_kill

(PHP 5, PHP 7, PHP 8)

mysqli::kill -- mysqli_killサーバーに MySQL スレッドの停止を問い合わせる

説明

オブジェクト指向型

public mysqli::kill(int $process_id): bool

手続き型

mysqli_kill(mysqli $mysql, int $process_id): bool

この関数は、process_id で指定した MySQL スレッドの停止をサーバーに問い合わせます。この値は、 mysqli_thread_id() 関数で取得したものである 必要があります。

実行中のクエリを停止するには、SQL コマンド KILL QUERY processid を使用する必要があります。

パラメータ

link

手続き型のみ: mysqli_connect() あるいは mysqli_init() が返す mysqliオブジェクト。

戻り値

成功した場合に true を、失敗した場合に false を返します。

エラー / 例外

mysqli のエラー報告 (MYSQLI_REPORT_ERROR) が有効になっており、かつ要求された操作が失敗した場合は、警告が発生します。さらに、エラー報告のモードが MYSQLI_REPORT_STRICT に設定されていた場合は、mysqli_sql_exception が代わりにスローされます。

例1 mysqli::kill() の例

オブジェクト指向型

<?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();
?>

手続き型

<?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

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top