Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new for PHP.Getting "MySQL server has gone away" error when i try to connect server using PHP. I can able access database with same credential in MySQL workbench. So, there is no problem in credentials.

Code:

$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'moodle';

$conn = mysql_connect($servername, $username, $password,$dbname);

Please suggest your solution.

What I have tried:

Googling for this error must of them suggest to set maximum for timeout . I tried that one. But not resolved.
Posted
Updated 6-Feb-17 5:09am

1 solution

Use PHP: mysqli::ping[^] to check whether the server has closed the connection and reconnect if necessary.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900