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
Functional Work : All functions perform similar work. All functions will include and evaluates the specific file while executing the code.
Functional Difference :
include vs include_once : There is only one difference between include() and include_once(). If the code from a file 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.
include vs require : if include() is not able to find a specified file 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 and 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 file 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/
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.