PHP mysqli_thread_id() 函数
示例 - 面向对象的样式
返回当前连接的线程 ID,然后杀死连接:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Get thread id
$thread_id = $mysqli -> thread_id;
// Kill connection
$mysqli -> kill($thread_id);
?>
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
// Get thread id
$thread_id = $mysqli -> thread_id;
// Kill connection
$mysqli -> kill($thread_id);
?>
查看底部的程序样式示例。
定义和用法
thread_id() / mysqli_thread_id() 函数返回当前连接的线程 ID,然后使用 mysqli_kill() 函数杀死该连接。
注释:如果连接被损坏且重新连接,线程 ID 将会改变。因此,仅当您需要的时候才获取线程 ID。
语法
面向对象的风格:
$mysqli -> thread_id()
程序风格:
mysqli_thread_id(connection)
参数值
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
技术细节
返回值: | 返回当前连接的线程 ID。 |
---|---|
PHP 版本: | 5+ |
示例 - 程序样式
返回当前连接的线程 ID,然后杀死连接:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit;
}
// Get thread id
$thread_id = mysqli_thread_id($con);
// Kill connection
mysqli_kill($con, $thread_id);
?>
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit;
}
// Get thread id
$thread_id = mysqli_thread_id($con);
// Kill connection
mysqli_kill($con, $thread_id);
?>