Should you always end mysql queries with “or die?”

前端 未结 6 1910
野的像风
野的像风 2020-12-19 10:09

Example queries in some tutorials ALWAYS end with:

or die(mysql_error());  

I can see why you would would sometimes want to do this, but t

6条回答
  •  鱼传尺愫
    2020-12-19 10:54

    but they even use this for queries that really shouldn't cause a problem

    Even the simplest SELECT * FROM FOO can cause a problem if the network between the web server and the database server falls over. It's good practice because when dealing with external systems such as databases, you really can't ever assume that something is 'safe'.

    In production code, you may not wish to use die() to handle errors - you could perhaps run some custom code to deal with it. At any rate, you should definitely handle the error in one way or another, and die() is a good way to start.

提交回复
热议问题