PHP mysqli_kill() Function

In this chapter you will learn:

  1. Definition for PHP mysqli_kill() Function
  2. Syntax for PHP mysqli_kill() Function
  3. Parameter for PHP mysqli_kill() Function
  4. Return for PHP mysqli_kill() Function
  5. Example - gets the thread ID for the current connection, then kills the connection
  6. Example - Object oriented style

Definition

The mysqli_kill() function asks the server to kill a MySQL thread specified by the processid parameter.

Syntax

PHP mysqli_kill() Function has the following syntax.

Object oriented style

bool mysqli::kill ( int $processid )

Procedural style

bool mysqli_kill ( mysqli $link , int $processid )

Parameter

ParameterIs RequiredDescription
connectionRequired.MySQL connection to use
processidRequired.The thread ID returned from mysqli_thread_id()

Return

It returns TRUE on success and FALSE on failure.

Example

The following code gets the thread ID for the current connection, then kills the connection.


<?php/*  j a  v a  2s.  co  m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");

if (mysqli_connect_errno($con)){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

// Get thread id
$t_id=mysqli_thread_id($con);

// Kill connection
mysqli_kill($con,$t_id);
?>

Example 2


<?php/*  ja v  a 2  s.co  m*/
$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);

// This should produce an error
if (!$mysqli->query("CREATE TABLE myEmp LIKE emp")) {
    printf("Error: %s\n", $mysqli->error);
    exit;
}

$mysqli->close();
?>

Next chapter...

What you will learn in the next chapter:

  1. Definition for PHP mysqli_more_results() Function
  2. Syntax for PHP mysqli_more_results() Function
  3. Parameter for PHP mysqli_more_results() Function
  4. Return for PHP mysqli_more_results() Function
  5. Example - checks if there are more results from a multi query
Home » PHP Tutorial » PHP MySQLi Functions
PHP mysqli_affected_rows() Function
PHP mysqli_autocommit() Function
PHP mysqli_change_user() Function
PHP mysqli_character_set_name() Function
PHP mysqli_close() Function
PHP mysqli_commit() Function
PHP mysqli_connect() Function
PHP mysqli_connect_errno() Function
PHP mysqli_connect_error() Function
PHP mysqli_data_seek() Function
PHP mysqli_dump_debug_info() Function
PHP mysqli_errno() Function
PHP mysqli_error() Function
PHP mysqli_error_list() Function
PHP mysqli_fetch_all() Function
PHP mysqli_fetch_array() Function
PHP mysqli_fetch_assoc() Function
PHP mysqli_fetch_field() Function
PHP mysqli_fetch_field_direct() Function
PHP mysqli_fetch_fields() Function
PHP mysqli_fetch_lengths() Function
PHP mysqli_fetch_object() Function
PHP mysqli_fetch_row() Function
PHP mysqli_field_count() Function
PHP mysqli_field_seek() Function
PHP mysqli_field_tell() Function
PHP mysqli_free_result() Function
PHP mysqli_get_charset() Function
PHP mysqli_get_client_info() Function
PHP mysqli_get_client_stats() Function
PHP mysqli_get_client_version() Function
PHP mysqli_get_connection_stats() Function
PHP mysqli_get_host_info() Function
PHP mysqli_get_proto_info() Function
PHP mysqli_get_server_info() Function
PHP mysqli_get_server_version() Function
PHP mysqli_info() Function
PHP mysqli_init() Function
PHP mysqli_insert_id() Function
PHP mysqli_kill() Function
PHP mysqli_more_results() Function
PHP mysqli_multi_query() Function
PHP mysqli_next_result() Function
PHP mysqli_num_fields() Function
PHP mysqli_num_rows() Function
PHP mysqli_options() Function
PHP mysqli_ping() Function
PHP mysqli_query() Function
PHP mysqli_real_connect() Function
PHP mysqli_real_escape_string() Function
PHP mysqli_refresh() Function
PHP mysqli_rollback() Function
PHP mysqli_select_db() Function
PHP mysqli_set_charset() Function
PHP mysqli_sqlstate() Function
PHP mysqli_ssl_set() Function
PHP mysqli_stat() Function
PHP mysqli_stmt_init() Function
PHP MySQL mysqli_thread_id() Function
PHP mysqli_thread_safe() Function