Conceptual Explanation


In this section, we give an overview of the concepts that will be explained and demonstrated in more detail in the rest of the book. Before proceeding, keep in mind that you, the reader of this text, are assumed to be the designer, creator, programmer, and writer of all the files involved. This includes any HTML documents and PHP and ASP files. (You are also assumed to be the database designer.)

Middleware: PHP and ASP

The PHP and ASP files are called scripts, and we will use that term and the term files. Scripts refer to files in languages that are stored more or less as you write them and translated into action when they are used. This “just-in-time” translation process often is called interpretation. In contrast, files in programming languages such as C++ and Java are translated into machine code in a distinct step in the development process. That translation process is called compilation. You, the creator/programmer/script writer, have placed your files on a computer that is connected to the Internet. This computer is called “the server.” The basic actions of the Web begin with a person sitting at a computer connected to what is called the Internet, invoking a program called a browser. Examples of browsers include:

  • All versions of Netscape

  • All versions of Microsoft Internet Explorer

  • All versions of Opera

  • Programs embedded in the product furnished by some Internet Service Providers (ISPs) such as AOL

This person, whom you might view as a member of your target audience, a customer, a client in the normal English meaning of the word, a friend, family member, and so forth, together with the computer is referred to as “the client.” The person enters an address into the location field of the browser. This address consists of a server name, a path, and a filename; for example, http://newmedia.purchase.edu/~Jeanine/index.html. The technical name for an address is Uniform Resource Locator (URL). The first part of the URL indicates the computer holding the file: newmedia.purchase.edu. It is the server. The browser responds to the person entering in a URL by sending a request for the particular file to the server computer (Figure 1.1).

click to expand
Figure 1.1: Request from client to server

This computer, running one of several possible server programs, receives this request and responds by sending the requested file to the client. The browser, upon receiving the HTML file, might determine that other files are referenced in the original file. Typically, these include image files. This means that the browser might submit more requests.

The process is more complex than just described. For example, the browser might determine that there is no need to send a request for a file, since the file is already on the client computer in an area called the cache. The path for the request might consist of many steps to get from client to server. The original HTML file might make references to files of various types; for example, a swf file holding a Macromedia Flash movie. In such a situation, the browser might use something called a plug-in or helper application to display the movie. If the browser cannot find an appropriate plug-in, it will display a window giving the person the option to save the file to the client computer. The browser’s next task (actually, it is done concurrently with making the additional requests) is to display the original HTML file and the referenced files as governed by the HTML standard. The HTML file can contain scripting code, typically in JavaScript, or, less commonly, VBScript. In this context, these are called client-side scripting. The execution of the script is performed by the browser on the client computer. The next chapter provides explanation and examples of basic HTML, and the following chapter discusses HTML forms and JavaScript. We mention only two possibilities here. You might include in your HTML file a hyperlink; that is, a text or image that when clicked by the client causes this entire process to begin again with a request from the browser for the specified address. Alternatively, you might include a form in which the person can enter information, including making choices from drop-down menus or clicking on check boxes. The HTML for the form indicates an address for handling the form.

Now, let us assume that you need to do something more complicated, such as produce an HTML file that is customized using data stored on the server computer in a database. One example could be that the person at the client computer is a potential customer who has chosen a category of products through making a selection in a form. For this situation, you will learn how to write PHP and ASP scripts to construct a customized Web page with information on products in the chosen category. The server program, upon receiving a request for a PHP or ASP script, does not simply send the file to the client. Instead, using programs installed on the server, these scripts are interpreted; that is, executed or run. In the situation described here, the PHP or an ASP script will access (no pun intended) a database and obtain information on products in the chosen category. The code (your code) uses that information to construct an HTML file. The server sends this customized HTML file to the client.

To develop an application using middleware, you will need to either have access to a server with programs such as Apache or Windows IIS, or make your own desktop computer into a server, using software such as Personal Web Server. To put it another way, an ordinary browser cannot interpret ASP or PHP files.

Systems Analysis and Design

Before jumping right into the technical considerations for building your application, you should stop and plan what the application is to do. Book examples and exercises typically do not require extensive analysis and design. However, to provide you with preparation for this very important step in systems development, we do devote a chapter on techniques and concepts useful for planning. Process modeling, also known as data flow diagramming, requires you, the developer, to identify the agents, processes, and data stores for your application. The requirement to identify agents means that you do not fall back on calling everyone connected with your project “users.” In the example we described, one agent is the customer or potential customer who has asked to view a set of products. The term data store applies to any collection of information for the project. A data store could be a (computer) database, but it could also be a file or information on a clipboard. Once you have defined the functionality of the application, and you make the decision to use middleware, you can use storyboarding to plan and document what scripts you will write and how they are connected. Storyboards are used for movies, animation, and other multimedia projects.

Databases

In computing, the term database refers to data organized in a specific fashion. Databases hold what are called tables; tables are made up of records, and records hold fields. An example of a database table would be a company catalog. (Figure 1.2 shows a special type of diagram, called an entity-relationship diagram, representing this database.) Each record in the catalog table holds information on a specific product. That information consists of a set of fields. Sample fields would be product identification number, product name, product category, product base cost, and the name of an image file that shows the product. The product identification number is called the primary key. It is possible for the database to hold the actual image file itself, but we will try this other approach, which is more common. Each record is called a row of the table, and fields are often called columns. Each record or row holds the same fields—different values for the fields, but the same fields. To make this example database more interesting, we will specify that it has a second table, called the category table. The records in the category table correspond to categories. Each category record has a category name, a category description, and a current discount rate to be applied to any product in this category. The value of a product category field in a product record in the catalog table would be the name of one of the categories. The product category field is called a foreign key since it essentially points to a record in another, a foreign, table. Several products might have the same product category field, meaning that they are in the same category. This connection represented by the field in one table referring to records in another table is called a relationship.

click to expand
Figure 1.2: Entity relationship diagram.

The design of a database, deciding what the tables should be, and what fields go in what records, is a complex task in its own right. Generally, more than one application makes use of a database. This makes it more challenging, but also more worthwhile to be careful in the design. In a later chapter, we will describe methods to improve the chances that a database design will serve the organization well over time. System developers often use diagrams for the design and documentation of databases. Products exist just for design and documentation. In this book, we will describe a technique called entity-relationship modeling. An ER model or ER diagram (ERD) shows the tables, the fields making up the records in each table, and the relationships between the tables. The symbols for the relationships also indicate the nature of the relationship, how many records in one table are related to how many records in another table.

There are other ways to organize data, but when the term database is used, it refers to data organized into tables, with tables holding records and records holding fields. The nice thing (where nice is too mild a word to express how wonderful and rare this situation is) is that there are many competing products that support databases, and though these products do have differences and compete based on these differences, they have much in common. For example, they all support the table, record, field model, and they all support a language for creating, querying, and modifying databases called Structured Query Language (SQL). For example, the following SQL statement will cause what is called a recordset to be created that holds the product names and base costs of all the products whose category is “chairs.”

    SELECT product_name, base_price FROM catalog      WHERE category_name='chairs'

Ignore the capitalization and the punctuation for now. This is a stand-alone SQL statement. We will show later how to issue such a statement from a PHP or ASP script. We give more examples of SQL later. The term for these products is database management system or DBMS. MySQL is a DBMS, as is Microsoft Access. Note: Access was not designed to be a multi-use DBMS for Web applications. However, it will work for our examples. We chose to use it because the Microsoft Office suite probably is already available to you. The proprietary “industrial-strength” DBMSs, such as SQL Server and DBII, tend to be expensive and require more effort to install. Since the basic mechanism of SQL is essentially the same for all database products, you will be able to apply what you learn here to other situations. The DBMS is a program running on the server that handles the SQL statements for reading and writing to databases.

Before presenting an overview of PHP and ASP scripts, we will describe what objects are in computing. Objects refer to information and procedures packaged together. Many different computing languages implement some form of objects. Both PHP and ASP use the methodology of objects, although in PHP, simple, built-in functions provide many of the facilities. In contrast, one can say that ASP is a set of objects. To use ASP, you need to use a scripting language, and we have chosen to use JavaScript, the same language that is most commonly used for client-side scripting. It also resembles, but is not identical to, the language of PHP.

The basic designs of PHP and ASP/JavaScript files are quite similar. Both files are text files and contain a mixture of HTML and PHP or ASP/JavaScript coding. The PHP or ASP sections are set off with delimiter symbols. The standard delimiters are <?php or <? and ?> for PHP, and <% and %> for ASP. Since we choose to use JavaScript for ASP, the first line of our ASP scripts should be:

    <%@ Language="JavaScript"%>

to indicate the scripting designation. You might go “in and out” of PHP or ASP when writing your scripts. For example, you might start an HTML tag outside of PHP, start PHP and write code to generate attribute values, and then end PHP and use straight HTML to close the tag.

When the server interprets the file, the HTML is output directly to the HTML document being created “on-the-fly” to be passed to the client computer. The non-HTML parts resemble other programming languages with assignment statements, expressions, procedure calls, and invocations of functions, object methods, and calls on object properties. To create the customized HTML page based on data from a database involves several steps. One of the steps uses expressions and assignment statements to create a character string that is the SQL command. This string becomes a parameter to a function or method that passes the command to the DBMS. Other functions or methods are used to take information from the result of the SQL statement and combine it with text and tags to create the HTML document sent to the client.

On the CD The workings of PHP and ASP/JavaScript are best described through examples, which we give in the next section, and in the rest of the book.




Creating Database Web Applications with PHP and ASP
Creating Database Web Applications with PHP and ASP (Charles River Media Internet & Web Design)
ISBN: 1584502649
EAN: 2147483647
Year: 2005
Pages: 125
Authors: Jeanine Meyer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net