mysqli::kill

mysqli_kill

(PHP 5, PHP 7, PHP 8)

mysqli::kill -- mysqli_killAsks the server to kill a MySQL thread

Description

Object-oriented style

publicmysqli::kill(int$process_id): bool

Procedural style

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

This function is used to ask the server to kill a MySQL thread specified by the process_id parameter. This value must be retrieved by calling the mysqli_thread_id() function.

To stop a running query you should use the SQL command KILL QUERY processid.

Parameters

mysql

Procedural style only: A mysqli object returned by mysqli_connect() or mysqli_init()

Return Values

Returns true on success or false on failure.

Errors/Exceptions

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.

Examples

Example #1 mysqli::kill() example

Object-oriented style

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

Procedural style

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

The above examples will output:

Error: MySQL server has gone away

See Also

To Top