Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

php include or require_once

Status
Not open for further replies.

connectionscentres

Programmer
Jan 5, 2005
16
GB
I have a small site of about 66 pages using php and mysql to offer various database driver services.

On each page where a database connection is required I have a php include directive at the top of the page. This includes a file where I make a single (non persistent) database connection each time.

However, I have just come accross the require_once directive. I am thinking that if I used this in conjunction with a persistent database connection I could merely invoke this when a user logs on and then forget about it for the remainder of the pages.

Does anyone have any suggestions from past experience as to whether this method is better?
 
You still need to invoke mysql_pconnect() with each script run. It's just that PHP will provide the script with the same database connection handle each time.

require_once() differs from require() only in that if you attempt to use an external file a second time with require_once() PHP will do nothing. With require, PHP will try to access the file again, which can cause problems with redefinition of classes, etc.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top