0

Where and how to write a code that will check if error showing "MySQL server has gone away" appears and print some error diferently and more nicely.

Warning: mysqli::mysqli() [mysqli.mysqli]: MySQL server has gone away
j0k
  • 22,600
  • 28
  • 79
  • 90
Davit
  • 1,394
  • 5
  • 21
  • 47

1 Answers1

1

There is another post that answers this (Solving "MySQL server has gone away" errors) with the following code snippet:

try {
  $conn = getDbConn();
  saveData($conn, $val);
} catch (DbException $e) {
  if (strstr($e->getMessage(), 'MySQL server has gone away') {
    // WRITE OUT NICE LOG HERE AND RETRY IF WANTED
    ....
    // RETRY
    $conn = getDbConn();
    saveData($conn, $val);
  } else {
    // we have a problem connecting or something, pass the exception along
    throw $e;
  }
}
Community
  • 1
  • 1
Aimon Bustardo
  • 158
  • 1
  • 7