【问题标题】:Warning: PDO::__construct() [pdo.--construct]: MySQL server has gone away , even with persistent connection警告:PDO::__construct() [pdo.--construct]: MySQL server has gone away ,即使有持久连接
【发布时间】:2012-08-06 11:32:14
【问题描述】:

我在我的应用程序中使用 PDO 来处理 MySQL。我已将其连接设置为持久。但是当我在 IDE 和浏览器之间切换以测试项目时,有时会出现以下错误:

警告:PDO::__construct() [pdo.--construct]: MySQL server has gone away in

这对我来说很奇怪,因为:

  1. 有时会在成功加载网页后发生(没有错误)。因此,我可以确保我在前几分钟建立了连接。
  2. 我使用了持久连接,我希望我不会失去与数据库的连接。

请帮帮我。

【问题讨论】:

  • 我认为当 mysql 不处理、提供数据时会发生这种情况。某种空闲模式

标签: mysql pdo connection warnings persistent


【解决方案1】:

根据this comment on a reported bug mysqlnd 正在内部捕获故障,将其报告为警告,然后重新建立连接。

(目前)禁止报告此警告的唯一方法是:

  1. 使用@运算符或
  2. 防止在构造函数执行期间报告警告:
    $oldErrorReporting = error_reporting();
    error_reporting($oldErrorReporting & ~E_WARNING);
    // construct PDO instance here
    error_reporting($oldErrorReporting);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 1970-01-01
    • 1970-01-01
    • 2013-12-16
    • 2011-12-11
    • 2022-01-11
    • 2011-02-04
    相关资源
    最近更新 更多