首页 > 解决方案 > 如何在读取问候包和 MySQL 消失时修复错误?

问题描述

我正在尝试将 mysqli 连接到系统。我编写以下代码:

连接文件

<?php
$mysqli = new mysqli('localhost', 'root', 'kemgh23','sistreatment') or die 
('cannot reach database');
if($mysqli === false){
die("ERROR: Could not connect. " . $mysqli->connect_error);
}
?>

运行此代码返回此错误:

 mysqli::real_connect(): MySQL server has gone away

 mysqli::real_connect(): Error while reading greeting packet. PID=16840

 mysqli::real_connect(): (HY000/2006): MySQL server has gone away
 Connection for controluser as defined in your configuration failed.

 mysqli::real_connect(): (HY000/2002): No connection could be made because the 
 target machine actively refused it.

 phpMyAdmin tried to connect to the MySQL server, and the server rejected the 
 connection. You should check the host, username and password in your 
 configuration and make sure that they correspond to the information given by the 
 administrator of the MySQL server.

标签: phpmysqli

解决方案


推荐阅读