INTRODUCTION TO PHP AND MySQL – BASIC DEVELOPMENT CONCEPTS

When developing a PHP application for the Web, the typical approach is to embed PHP code into one or more standard HTML documents using special “tags” or delimiters.

Here’s an example:

When such a document is requested by a user, a PHP-aware we server can recognise and execute the PHP code blocks and interpolate the resulting output into the HTML document before returning it to the requested user. The result – a web page or application that almost seems alive – responding intelligently to user actions by virtue of the PHP program logic embedded within it.

Here is what is happening:

1. Joe opens his web browser at home and types in the URL to a website. After looking up the domain, Joe’s browser (the client) sends an HTTP request to the corresponding server IP address.

2. The web server handling HTTP requests for the domain receives the request and notes that the URL ends with a .php suffix. Because the server is programmed to automatically redirect all such requests to the PHP layer, it simply invokes the PHP interpreter and passes it the contents of the named file.

0c862cec8e5425bfd3dd2b98a607280b.doc Page 1 of 3 Version 1 3. The PHP interpreter parses the file, executing the code in the special PHP tags. Within these tags, you can perform calculations, process user input, interact with a database, read and write files…the list goes on! Once the script interpreter has completed executing the PHP instructions, it returns the result to the browser, cleans up after itself, and goes back into hibernation.

4. The results returned by the interpreter are transmitted to Joe’s browser by the web server.

0c862cec8e5425bfd3dd2b98a607280b.doc Page 2 of 3 Version 1 Client-Server Framework

From the preceding explanation, it should be clear that to get started building PHP applications, your development environment must contain at least three components:

1. A base operating system (OS) and server environment (usually Linux) 2. A web server (usually Apache on Linux, or IIS on Windows) to intercept HTTP requests and either serve them directly or pass them on to the PHP interpreter for execution 3. A PHP interpreter to parse and execute PHP code, and return the results to the Web server

There’s also often a fourth optional but very useful component:

4. A database engine (such as MySQL) that holds application data, accepts connections from the PHP layer, and modifies or retrieves data from the database

An important corollary of this approach is that the PHP code is executed on the server, and not on the client browser. This allows web developers to write program code that is completely independent of, and thus impervious to, browser quirks - an important advantage over client-side scripting languages, such as JavaScript, which often require complex logic to account for browser-specific differences. Further, because the code is all executed on the server and only the output is sent to the client, it is impossible for users to see the source code of your PHP program - an important security advantage over languages like JavaScript.

0c862cec8e5425bfd3dd2b98a607280b.doc Page 3 of 3 Version 1