Helping ordinary people create extraordinary websites!

Putting PHP & MySQL To Work

By Steve Fox
2004-05-11

Reusable modules are key
When you create dynamic Web sites, you should use reusable modules, usually done by functions and include files. By forcing your code into modules, you can decrease the complexity of your code. Most experienced programmers already know this, but many overlook the importance of modularity when it comes to Web sites. Any time you find yourself using the same technique more than once, consider making a function for it, as in the following PHP example:

function name ($var) {
// code goes here
}

The scope of the $var variable is the name function. Before you can reference global variables in a function in PHP, you need to use the global keyword to define them. If a function will only be used on one page, you can simply include it in the same script that will reference the function. If more than one script will use this function, consider putting it in a separate file that can be imported by any script.



Tutorial pages:
 1 Votes

You might also want to check these out:


Leave a Comment on "Putting PHP & MySQL To Work"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS