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

后端 未结 4 1984
甜味超标
甜味超标 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条回答
  •  [愿得一人]
    2020-12-02 09:01

    If the first statement returns true, then the entire statement must be true therefore the second part is never executed.

    For example:

    $x = 5;
    true or $x++;
    echo $x;  // 5
    
    false or $x++;
    echo $x; // 6
    

    Therefore, if your query is unsuccessful, it will evaluate the die() statement and end the script.

提交回复
热议问题