|
| PHP Reference Sites |
| Official PHP Page |
PHP was created in the fall of 1994 by Rasmus Lerdorf. Early, private version were used to keep track of who was looking at his on-line resume. Public versions came in 1995. Those consisted of a very simplistic parser engine that only understood a few special macros and some common utilities for home pages. A guest-book, a counter and some other stuff.
Later in 1995 PHP/FI version 2 came out. It included a rewritten parser. The FI was another package that Rasmus had written which handled HTML form data. People enjoyed it and started contributing code to it. Later version 3 was released. This contained many improvements and changes, including an entirely rewritten parser. Now version 4 is nearly released which is better even yet.
As you can see, PHP was written to fill the needs for simple and complex dynamic HTML pages. It supplies integration with LDAP, many databases, image tools, and even PDF writing libraries. It was written to fill a specific need. This might make it one of the best tools for the job.
Now that you know why it was created, let me tell you why myself (and likely many other web designers and programs are glad). PHP is clean and fast. It is very much like the best of the C and Java programming languages. It provides one with simple, fast database access. Honestly, it was designed specifically with the web in mind. Now, like any chef I prefer to use the right knife for the job... and the sharper the better.
PHP is powerful enough that it could be used for other purposes. I do not know if there is a stand alone interpreter or not (it seems there is, but it may not be a supported mode of operation). If there is, I have yet to hear of any projects using it. Just be aware you are likely to see it used in the near future for other things than web pages.
For the past 10 years there have been two major buzz words in the programming industry. One is Object Oriented Programming, which has a nice philosophy, but is usually poorly implemented in languages and compilers causing executables to run slowly and to take up much more memory than traditional techniques. The other is Rapid Application Development (RAD). In the past RAD was usually only used for prototypes and proof of concepts. They were quick, dirty and usually not production quality. Some of this was the programmer's fault. Much was at the door of the tool, though.
In late 1999 PHP became widely accepted, so it was easy to use for yourself or your customers. This was a tremendous breakthrough in programming; particularly for web programming. This was because PHP, with a little learning and experience behind you, allowed you to do Rapid Prototyping and Development in a far more elegant, speedy, efficient and integrated fashion. With a little discipline, a programmer, with some experience, could turn out a prototype in "no time flat". These prototypes would be so clean and well laid out, that it was easy to just clean them up and finish the development from that code base. With most RAD tools, you had to start over in a different tool and/or code-base.
Woah, there. Not so fast! Yes, PHP is a dang fine tool. It, combined with a good knowledge of HTML, can provide you with most of what you need, but there are a few places where it is not enough. Often times, you will still want to use some client side scripting, such as Javascript, to further enhance the function and look of your site that you could not do with server side work alone. So, now you have three tools (HTML, PHP, Javascript).
Depending on the amount of processing horsepower needed and the complexity of your task, PHP could very well be the wrong solution, even if it would provide a working version. This is not because of a failure for PHP. It is just not what it was designed for. Let us say you were allowing customers to create a card or invitation on-line. This card/invitation may or may not be created from scratch by the customer. It is likely to be based on some templates. So, far, so good. PHP could do this. Now lets say that the layout is quite complex. It involves images and transparencies (alpha channels), fonts, colors, and simulation of paper backdrops.
Well, PHP could probably do this. The reason we would not want to is because of server horsepower and network bandwidth. This are simple tasks, but it would burden the server time wise, and the client or server may not have enough network bandwidth to provide the resulting image samples in reasonable amounts of time. Here we must step over to Java. It works well as a client side language (though there are some problems due to browsers), it can be integrated with the browser. Not only that, but suddenly our server has to do much less work and the client gets all the needed images once. No asking for a composite, because the client's machine does the work for it.
Now what if you have a complex task that cannot be handed off to the client, but needs to be done fast and efficiently and PHP doesn't do this. Well, then it is time for server side Java, C, or C++. I personally prefer C with FastCGI integration with the web server. Your choices, experiences and tastes will vary what you choose, why, and how successful it will be.
All in all, PHP is very fast and versatile. I recommend it for all projects where timely persistence does not matter. An exception to that might be when it makes sense to split it into some sort of client/server model of computing, such as the above invitation example.
"Ok, we know how great it is. We know when to use it and when not to. We know how well suited it is... but we don't have a clue how to use it." Well, never fear. Below is an example. It assumes that you had a web page that used the post method in a form to send variable USER_NAME to the server and request a resulting page. Please note, never use a user name as a password, as I have done here. It is a REALLY bad idea.
1 <html>
2 <head>
3 <title>Example</title>
4 </head>
5 <body>
6 <?PHP
7 $USER_NAME=HTTP_POST_VARS['USER_NAME'];
8 echo "Hello, " .$USER_NAME;
9 $conn = @pg_pconnect("dbname=ecommerce host=example.com user=$USER_NAME password=$USER_NAME");
10 $customers=pg_Exec($conn, "select fname, lname from customers");
11 echo "<center><table border="3"><tr><th colspan=\"2\"gt; Customers</th></tr>";
12 echo "<tr><th>Last Name</th><th>First Name</th></tr>";
13 for($i=0; $i < pg_NumRows($customers); $i++)
14 {
15 $row=pg_Fetch_Array($customers, $i);
16 echo "<tr><td>";
17 echo $row['lname'];
18 echo "</td>";
19 echo "<td>";
20 echo $row['fname'];
21 echo "</td></tr>";
22 }
23 echo"</table></center>";
24 ?>
25 </body>
26 </html> |
The above example queries a PostgreSQL database table named customers in a database named ecommerce. It would then output a table that looked a bit like this:
| Customers | |
|---|---|
| Last Name | First Name |
| Smith | John |
| Olsen | Fred |
| Adams | Quincy |
| Oulafendotter | Frodo |
With a line of text above it that would say: "Hello, Trever"
I hope this little tutorial has helped you. You will notice that in many regards, it is C and Java like. There is some similarity to Perl and BASIC, as well. If you need more help or information, please go to one of the sites above. The official site for PHP has many links to tutorials and articles. Best of luck!
| ||
| Email Vichu | ||
| Site Map | Link Partners | |
| Recommended Intake | ||
![]() | ||
Copyright © 2000-2006 by Trever L. Adams.
All Rights Reserved.