<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* 检查连接是否成功 */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* 获得连接对应的线程 ID */
$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();
}
/* 获得连接对应的线程 ID */
$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