require or include??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Indium
Forum Newbie
Posts: 15
Joined: Tue Jul 02, 2002 8:30 pm

require or include??

Post 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
Last edited by Indium on Mon Jul 22, 2002 9:36 pm, edited 1 time in total.
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
User avatar
musashi
Forum Commoner
Posts: 39
Joined: Tue Jul 23, 2002 12:51 pm
Location: Santa Cruz - CA

Closing the database

Post 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);
Post Reply