Keep checking for errors in queries

发布于 2022-09-06 10:19:34 字数 490 浏览 12 评论 0

I'm a bit obsessed now. I'm writing a PHP-MYSQL web application, using PDO, that have to execute a lot of queries. Actually, every time i execute a query, i also check if that query gone bad or good. But recently i thought that there's no reason for it, and that's it is a wast of line to keep checking for an error.

Why should a query go wrong when your database connection is established and you are sure that your database is fine and has all the needed table and columns?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慕烟庭风 2022-09-13 10:19:34

You're absolutely right and you're following the correct way.

In correct circumstances there should be no invalid queries at all. Each query should be valid with any possible input value.

But something still can happen:

  • You can lose the connection during the query
  • Table can be broken
  • ...

So I offer you to change PDO mode to throw exception on errors and write one global handler which will catch this kind of errors and output some kind of sorry-page (+ add a line to a log file with some details)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文