Example: 1. This is the content of conn. php :? Php $ connmysql_connect (localhost,); mysql_select_db (php );? 2. Call functionfun ($ a) {include (conn. php );....... database processing statement }..... fun (aaa); First Time
Example: 1. This is the content of conn. php :? Php $ conn = mysql_connect ('localhost', '',''); mysql_select_db ('php ');? 2. If you call function fun ($ a) {include (conn. php );....... // database processing statement }..... fun (aaa); // The First Time
Example:
1. This is the content of conn. php:
$ Conn = mysql_connect ('localhost ','','');
Mysql_select_db ('php ');
?>
2. If the call is as follows:
Function fun ($)
{
Include ("conn. php ");
... // Database processing statement
}
.....
Fun ("aaa"); // The first call
.....
Fun ("bbb"); // second call
An error occurs during the second call, but changing include to require will not cause any problem.
Because the require file is called only once when the page is read, and the include file is called in every call that contains fun, the database connection is re-connected before it is closed.
Therefore, you only need to call require once in a loop. Both can be used elsewhere.
3. include () generates a warning and require () causes a fatal error. In other words, if you want to stop processing the page when a file is lost, use require (). This is not the case with include (). The script will continue to run.