How to fix error while reading greeting packet and MySQL has gone away?

Viewed 329

Im trying to connect mysqli to the system.I write this code as below:

conn.php

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

Running of this code return this errors:

 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.
0 Answers
Related