isconnected() return true 虽然 mysql 服务器在 zend 框架中消失了

isconnected() return true though mysql server gone away in zend framework

我正在使用 zend 框架 application.I 是 运行 server.Somehow 上的一个邮件发送脚本 我在 5 分钟后收到来自 SMTP 服务器的响应 同时 mysql 服务器由于 mysql 等待超时 setting.I 已消失 已检查连接是否处于活动状态。我用过

$db->isConnected();

但它总是 return 正确,尽管 mysql 服务器消失了 away.I 无法理解 isConnected.Anyone 的含义,请解释一下数据库连接是如何工作的?

来自手册(强调我的):

Since release 1.7.2, you could check you are currently connected to the RDBMS server with the method isConnected(). This means that a connection resource has been initiated and wasn't closed. This function is not currently able to test for example a server side closing of the connection. This is internally use to close the connection. It allow you to close the connection multiple times without errors.

http://framework.zend.com/manual/1.12/en/zend.db.adapter.html

换句话说,这是跟踪连接状态从您的代码 - "did I connect yet? did I disconnect already?",而不是从底层 TCP 隧道的角度来看。

(怎么办:从技术上讲,无论如何您都应该捕获 SQL 异常,因此如果此问题发生在特定点,您可以检查那里是否断开连接(例如使用 $db->query('SELECT 1')) , 如果抛出此异常则重新连接。)