0

When I try to run the below program I am get error as MySQL server has gone away.

<?php
$servername = "localhost";
$username = "root";
$password = "";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

Google says that it is due to

2

Try to debug the problem. This can be caused by any number of things. Commonly there are:

  • The MySQL server crashed
  • A comms problem between the client and server
  • Abusing the client library in a way not intended, perhaps sending commands out of order or sending junk through the socket.

I came to solution as to debug the problem. How to debug to find the correct reason as to why this error is happening?

Dharman
  • 30,962
  • 25
  • 85
  • 135
gokul
  • 109
  • 10
  • Please read https://stackoverflow.com/questions/58808332/should-we-ever-check-for-mysqli-connect-errors-manually – Dharman Jan 14 '20 at 16:10

1 Answers1

0

First check version of php installed in your computer

The MySQLi extension is designed to work with MySQL version 4.1.13 or newer.

if you have required version

am suggesting you to unistall your server for example if is xampp then install it again

it will work

MecaTheclau
  • 188
  • 1
  • 3
  • 14