(PHP 5, PHP 7, PHP 8)
mysqli::kill -- mysqli_kill — 让服务器杀死一个 MySQL 线程
面向对象风格
过程化风格
本函数可以用来让服务器杀掉 process_id
参数指定的 MySQL 线程。必须通过调用 mysqli_thread_id() 函数来检索该值。
要停止正在运行的查询,应该使用 SQL 命令 KILL QUERY processid
。
mysql
仅以过程化样式:由 mysqli_connect() 或 mysqli_init() 返回的 mysqli 对象。
If mysqli error reporting is enabled (MYSQLI_REPORT_ERROR
) and the requested operation fails, a warning is generated. If, in addition, the mode is set to MYSQLI_REPORT_STRICT
, a mysqli_sql_exception is thrown instead.
示例 #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();
}
$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();
}
$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