PHP/MySQL made simple

Apr 11 2008   3:25PM GMT

An introduction

Jon Harris Profile: Jonsjava

Tags:
Exchange Server ActiveSync

Prelude
There are many sites out there that offer a good list of software to help you program PHP, as well as a good number of websites that help you out with a project by linking you to great open-source products that server a purpose. This will not be one of those sites. This site will be for those of you who already have your program of choice, be it a $500.00 IDE or just notepad, but you need pointers on how to do something, and can’t find a good place to get the info.

Background
I started programming in PHP because, well, I needed some money. Since then, I have become fairly proficient in the language. You will almost never see me write Object-Oriented (O-O) scripts, and rarely use case statements. That doesn’t mean that I don’t know how, it simply means that I prefer the style I use. There are many ways to write a PHP program, and some are better than others. What I am going to be offering for you is the basic idea for code, and a working sample, with a good explanation on how it works, as well as why I do it that way. Hopefully I will show you good ways to program, as well as open you up to the possibility to the fact that there are other ways to program other than Object oriented programming.

Example
The first example I will use is a fun one. There is a site, 99 bottles of beer.net, who’s goal is to have a repository of programming source code that when executed will generate the full song “99 Bottles of Beer on the Wall“. Most people will use a class that will return the value of the bottle until you reach 0, then print the final line:

No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.

I don’t like wasting code. I’m a firm believer that programmers have more important things to do than write useless lines of code, when just a few, short lines will do. My solution to this challenge? This:

*EDIT*Could not leave script in and keep rest of post looking correct. to view code, go to http://vent.jonsjava.com/beer.txt

What this script does is this:

  • sets the max number of beers ($count=99)
  • prints out each verse until it reaches zero, decreasing the number of bottles each time (–$count)
  • Once it reaches zero, it prints the final verse, then it’s done

(To see the code in action, go to http://vent.jonsjava.com/beer.php

Do you really need a 75-line class to do this? It may not be pretty, but it’s a good proof of concept.

In the Next Issue
I will be discussing how to write an intelligent password generator

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: