简体   繁体   English

捕获“警告:mysqli :: mysqli()[mysqli.mysqli]:MySQL服务器已消失”以很好地编写错误

[英]Catch “Warning: mysqli::mysqli() [mysqli.mysqli]: MySQL server has gone away” to write error nicely

出现在何处以及如何编写代码,以检查显示“ MySQL服务器已消失”的错误,并更好地打印出一些错误。

Warning: mysqli::mysqli() [mysqli.mysqli]: MySQL server has gone away

There is another post that answers this ( Solving "MySQL server has gone away" errors ) with the following code snippet: 还有另一篇文章用以下代码片段回答了这个问题( 解决“ MySQL服务器已离开”错误 ):

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;
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM