The error message is very self explaining – the program lost connection to the server. The reason for this error is quite often simply that the script took longer time to execute than the time-out settings in the connection. In PHP there is a simple command to check if the database connection still is open: