include, include_once, require or require_once?

Viewed 49396

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.

8 Answers
<?php

include('db.php');   

echo "<br>"."Included"."<br>";

include_once('db.php');

echo "<br>"."Again included"."<br>";

?>

In the Above Code, I have included a file using include statement at the top, the file get included.

Next I have used include_once to include the same file, But as the file was already included above, it will not be included again here.

Output:

Connected             -----This is from db.php File
Included

Again included

<?php

include_once('db.php');

echo "<br>"."Again included"."<br>";

include('db.php');

echo "<br>"."Included"."<br>";

?>

I have used include_once at the top in the above code, so the file is included.

But in the next code I have again used include_once for the same file, then again the file will be included and the output will be:

Output:

Connected
Again included
Connected
Included
Related