include, include_once, require or require_once?(包括、include_once、require 还是 require_once?)
问题描述
I have PHP file where I have defined the server access variables as well as the mysql_connect
and mysql_select_db
, as this functions are regularly used in almost every page in backend, while I am using include()
which is perfectly working for me now, which method or function would you suggest and I would like to know if there is any flaw if I use include()
or is it safe to use it?
Edit : Keeping in mind I'll be using $_SESSION
variable too.
The only difference between the two is that require
and its sister require_once
throw a fatal error if the file is not found, whereas include
and include_once
only show a warning and continue to load the rest of the page. If you don't want PHP to attempt to load the rest of your page without the database info (which I would assume), then use require_once
. You don't need to include the file more than once, so there is no need to use the regular require
function.
这篇关于包括、include_once、require 还是 require_once?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:包括、include_once、require 还是 require_once?
基础教程推荐
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01