开发者

Keep checking for errors in queries

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 开发者_JAVA技巧and columns?


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜