How does “do something OR DIE()” work in PHP?

后端 未结 4 1986
甜味超标
甜味超标 2020-12-02 08:24

I\'m writing a php app to access a MySQL database, and on a tutorial, it says something of the form

mysql_connect($host, $user, $pass) or die(\"could not con         


        
4条回答
  •  -上瘾入骨i
    2020-12-02 08:49

    It works as others have described.

    In PHP, do not use "die", as it does NOT raise an exception (as it does in Perl). Instead throw an exception properly in the normal way.

    die cannot be caught in PHP, and does not log - instead it prints the message ungracefully and immediately quits the script without telling anybody anything or giving you any opportunity to record the event, retry etc.

提交回复
热议问题