Jump to content

Confused with include and include_once


terryds
 Share

Recommended Posts

The difference Include_once and include (same as require_once and require) is that *_once will check if the file was included/required before, it will not include it again.

And the difference between include and require is that require will stop the execution of the script if it cannot find the file required and generate a fatal error. While include will only issue a warning and continue the execution of the script.

 

 

So for essential code, as in this case DB connection, require_once is best.

  • Like 1
Link to comment
Share on other sites

It depends what the code that you are including does. If you are including a file that defines a class, for example, then you only want to include that file once. If the file contains code that you want to execute repeatedly whenever you include it, then you would not want to only include it once.

Link to comment
Share on other sites

i would go with require_once().. i always use that php function to get my db-connection file...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...