“做某事或DIE()”如何在PHP工作? [英] How does "do something OR DIE()" work in PHP?
本文介绍了“做某事或DIE()”如何在PHP工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个php应用程序来访问MySQL数据库,在教程中,它表示一些形式
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 connect");
PHP如何知道该函数失败,以便运行该模块?我想我在问这个或部分是如何工作的。我不认为我以前见过它。
How does PHP know that the function failed so that it runs the die part? I guess I'm asking how the "or" part of it works. I don't think I've seen it before.
推荐答案
如果第一个语句返回 true
,则整个语句必须是 true
因此第二部分永远不会执行。
If the first statement returns true
, then the entire statement must be true
therefore the second part is never executed.
例如:
$x = 5;
true or $x++;
echo $x; // 5
false or $x++;
echo $x; // 6
因此,如果您的查询失败,它将评估 die()
语句并结束脚本。
Therefore, if your query is unsuccessful, it will evaluate the die()
statement and end the script.
这篇关于“做某事或DIE()”如何在PHP工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文