EXPLAIN INCLUDE(),REQUIRE(),INCLUDE_ONCE() AND REQUIRE_ONCE() FUNCTIONS IN PHP

I have sầu PHP file where I have defined the VPS access variables as well as the mysql_connect và mysql_select_db, as this functions are regularly used in almost every page in backkết thúc, while I am using include() which is perfectly working for me now, which method or function would you suggest & I would lượt thích to lớn 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 tệp tin is not found, whereas include & include_once only show a warning và continue lớn load the rest of the page. If you don"t want PHPhường khổng lồ attempt khổng lồ load the rest of your page without the database info (which I would assume), then use require_once. You don"t need khổng lồ include the file more than once, so there is no need lớn use the regular require function.

Bạn đang xem: Explain include(),require(),include_once() and require_once() functions in php


*

Functional Work : All functions perkhung similar work. All functions will include & evaluates the specific tệp tin while executing the code.

Functional Difference :

include vs include_once : There is only one difference between include() và include_once(). If the code from a tệp tin has been already included then it will not be included again if we use include_once(). Means include_once() include the file only once at a time.

Xem thêm: Whereas Là Gì - Phân Biệt Các Từ : But, While, Whereas

include vs require : if include() is not able khổng lồ find a specified tệp tin on location at that time it will throw a warning however, it will not stop script execution. For the same scenario, require() will throw a fatal error và it will stop the script execution.

require vs require_once : There is only one difference between require() and require_once(). If the code from a tệp tin has been already included then it will not be included again if we use require_once(). Means require_once() include the file only once at a time.

To get the detailed knowledge with example please review these amazing articles (1) http://www.readmyviews.com/include-vs-include-once/ (2) http://www.readmyviews.com/include-vs-require/