Page 1 of 1

require or include??

Posted: Mon Jul 22, 2002 9:26 pm
by Indium
I have a login.php file that contains the username etc and logs into the database. I have used require_once("login.php") and also include("login.php") in other files. They both work. Which one should I use and when?

Also, how do I go about closing a database connection if I am including (or "requiring") a link to the login.php file? I have tried putting in mysql_close($databasename) in my php files but I just get an error message.

Sorry if this seems like two posts in one, but they are somewhat related.

Thanks

Posted: Mon Jul 22, 2002 9:34 pm
by jason
I pretty much use the *_once() functions whenever I need to include something. Use require_once() when something needs to be included or the script just won't run, and include_once otherwise.

Closing the database

Posted: Tue Jul 23, 2002 1:02 pm
by musashi
In response to closing the database, you stated you put:

mysql_close($databasename)

Just to make sure, since you said $databasename, you do mean $databaselink right? The mysql_close command works by closing a link not a dbname. Assuming that isn't the problem, to avoid the error message, you need some way of "closing" the db, only if you've opened it. So you could set a flag (some signifying variable, such as $dbflag = true), and then make the mysql_close command conditional. Ex:

if($dbflag) mysql_close($databaselink);