Matt Lowden

Fixing "MySQL server has gone away"

June 14th 2013

This is a simple solution to the problem "PDOException: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away" or just "MySQL server has gone away", which often occurs whilst running long scripts that periodically execute SQL queries.

The problem is a result of a long period of time between two SQL queries, during which the database connection is dropped.

The following query should be executed before a long period of script execution.

PDO
$pdo->query("SET wait_timeout=6000");
MySQL
mysql_query("SET wait_timeout=6000", $database_connection);

Put simply the above code will allow up to 6000 seconds to pass before a database connection automatically drops.

cialis online

Köpa Generisk viagra online i sverige