MySQL Forums
Forum List  »  PHP

Re: Connecting to MySQL on numerous pages
Posted by: Rick James
Date: March 16, 2012 09:37AM

Drop the DLL stuff; keep the connect stuff.
Suggest you create an "include" file that has a function with the connect code. Each PHP script would 'require' that file. Then call that function at the start. (The disconnect is good practice, but optional -- when php finishes, it will close the db connection.)

Little by little, you may find yourself adding more subroutines to the include file. I usually end up with as much code in includes as in PHP; often with includes 'requiring' other includes.

Structuring your code and reusing your code (via functions) -- good practice.
Repeating code -- bad practice.

Think of the tedium and risk if you switched providers and had to change this in dozens of files:
$hostname = "hostname.isp.com";

Options: ReplyQuote


Subject
Written By
Posted
Re: Connecting to MySQL on numerous pages
March 16, 2012 09:37AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.