terryds Posted September 14, 2013 Share Posted September 14, 2013 I don't know when to use include_once .. For every connect to the database server, should i use include/require_once or just include/require ? If not, why ? Link to comment Share on other sites More sharing options...
Lulzim Posted September 14, 2013 Share Posted September 14, 2013 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. 1 Link to comment Share on other sites More sharing options...
justsomeguy Posted September 16, 2013 Share Posted September 16, 2013 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 More sharing options...
rootKID Posted September 18, 2013 Share Posted September 18, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now