PDO fetch()是否在失败时抛出异常? [英] Does PDO fetch() throw an exception on failure?

查看:164
本文介绍了PDO fetch()是否在失败时抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法 PDOStatement :: fetch()会将异常抛出失败,如果PDO错误报告系统设置为抛出异常?例如。如果我设置:

Does the method PDOStatement::fetch() throw an exception on failure, if the PDO error reporting system is set to throw exceptions? E.g. if I set:

PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION

你知道这样的情况吗?

非常感谢。

方法 PdoStatement :: fetch 在失败时抛出异常,而不是 FALSE 。在我的答案中证明了这种情况:

The method PdoStatement::fetch throws indeed exceptions on failure, instead of FALSE. Such a case is demonstrated in my answer:

总而言之:


  • PDOStatement :: fetch 如果没有记录,则返回 FALSE

  • PDOStatement :: fetch 在失败时抛出异常。

  • PDOStatement::fetch returns FALSE if no records are found.
  • PDOStatement::fetch throws exceptions on failure.

推荐答案

here 声称fetch()抛出异常。我会非常小心,假设它不会或不会抛出异常,因为它们在准备或绑定时通常被抛出。把这个电话放在一个try块里是一个很好的理由。所以为了回答这个问题,在这个非常不可能的失败的情况下,是的,fetch()应该抛出一个异常,在这种情况下呢。现在看看是否还有其他情况会很有趣。

The user here claims that fetch() threw an exception. I'd be very careful in assuming that it doesn't or won't throw an exception just because they are typically thrown when you prepare or bind. This is a very good reason to put the call inside a try block. So to answer the question, in the highly unlikely event of failure, yes fetch() should throw an exception and in that one case it did. Now it will be interesting to see if there are other cases as well.

这篇关于PDO fetch()是否在失败时抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆