mysqli::kill
mysqli::kill
mysqli_kill
(PHP 5, PHP 7)
mysqli :: kill - mysqli_kill - 请求服务器杀死一个MySQL线程
描述
面向对象的风格
bool mysqli::kill ( int $processid )
程序风格
bool mysqli_kill ( mysqli $link , int $processid )
这个函数用来请求服务器杀掉processid
参数指定的MySQL线程。必须通过调用mysqli_thread_id()函数来检索此值。
要停止正在运行的查询,您应该使用SQL命令KILL QUERY processid
。
参数
`link`
仅过程样式:由mysqli_connect()或mysqli_init()返回的链接标识符
返回值
成功返回TRUE或失败时返回FALSE。
例子
示例#1 mysqli :: kill()示例
面向对象的风格
<?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_thread_id() - 返回当前连接的线程ID
← mysqli::$insert_id
mysqli::more_results →