问题描述
问题
我们告诉PDO将每个问题包装成异常.在某些情况下,它会生成一些警告,然后才引发异常.
We tell PDO to wrap each issue into exception.In some cases it generates a few warnings and only then throws exception.
为什么这样做?
重复吗?
对此,尚无正确答案.最后一个问题是 PHP PDO异常+ MySQL警告已消失?,但是人们只是将其标记为重复,而不是仔细回答.
There were no correct answers on SO regarding it. Last question was PHP PDO Exception + Warning on MySQL Has Gone Away? but people just marked it as duplicate instead of carefully answer.
接受的答案不能回答为什么这样做以及何时这样做.因此,我进行了研究并将回答.
Accepted answer not answers why does it do it and when. So I researched and will answer.
推荐答案
这是因为PDO可以使用mysqlnd驱动程序,因此不遵循PDO的任何将问题转换为扩展"政策.
It's because of PDO could use mysqlnd driver, which not respects any of PDO's "convert-issues-to-extensions" policy.
只需查看 mysqlnd驱动程序的来源.
我们清楚地看到有直接呼叫php_error_docref
.
We clearly see there direct calls to php_error_docref
.
其中一个示例,显示在上一个问题由以下几行解释: https://github.com/php/php-src/blob/PHP-5.5.31/ext/mysqlnd/mysqlnd_wireprotocol.c#L35:L61
And one of examples, shown at previous question explained by these lines: https://github.com/php/php-src/blob/PHP-5.5.31/ext/mysqlnd/mysqlnd_wireprotocol.c#L35:L61
这篇关于当PDO告诉我们不要这样做时,为什么会生成警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!