How does quot;do something OR DIE()quot; work in PHP?(“做某事或死()如何?在 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 是如何知道函数失败以便运行 die 部分的?我想我在问它的或"部分是如何工作的.我想我以前没见过.
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.
这篇关于“做某事或死()"如何?在 PHP 中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“做某事或死()"如何?在 PHP 中工作?


基础教程推荐
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01