我正在研究zend框架应用程序.我在服务器上运行一个邮件发送脚本.我正在从SMTP服务器5分钟后得到响应同时mysql服务器已经消失,因为mysql等待超时设置.我已检查该连接是否处于活动状态或不.我用过
$db->isConnected();
但它总是返回true虽然MysqL服务器消失了.我无法理解isConnected.Anyone的意思解释我如何连接db连接?
解决方法:
从手册(强调我的):
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
换句话说,这是跟踪从代码中看到的连接状态 – “我连接了吗?我已经断开了吗?”,而不是从底层TCP隧道的角度来看.
(做什么:从技术上讲,你应该抓住sql异常,所以如果在特定点发生这个问题,你可以检查那里的断开连接(例如使用$db-> query(‘SELECT 1’)),以及如果抛出此异常,则重新连接.)