Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

PHP MySQL Require

In PHP with MySQL what is the difference between require, require once and include?
Also which is the best use.

Finally, to close a BD conection do I just used <?php mysql_close; ?> at the bottom of a script?
Avatar of mattibutt
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
for the difference:

and yes, call mysql_close(); at the end of script... don't forget those brackets - ()
Avatar of Marco Gasi
1): If you use include function and included file is not found, you'll get a warning but script will be executed (if it's doesn't depend by something contained in included file); if you use require, file required is supposed to be necessary to execute script and if it is not found php raises a fatal error.
With require_once, you say to php to  include a file only if it has not been required or included before by some other script: this is useful if file required contains some function,because you can't declare the same function more than once.

2) Yes to close a db connection just use <?php mysql_close; ?> at the bottom of a script

Avatar of Robert Granlund


Yes to close a db connection just use <?php mysql_close; ?> at the bottom of a script

Does it need to be before the </html> or </body>?
it doesnt matter you can put where ever you want