On the CD In this section, we show some examples of diagrams and code fragments. The samples shown here are simple php and asp code. The CD-ROM contains the code in the folder named chapter1code.
The term entity is a fancy name for thing. Entities might be concrete things that exist in a business or organization, such as customers and products, or they might be abstract or ephemeral, such as an order number-product number pair that represents part of a customer’s order. Any single entity is represented by certain information, and the items of information are called attributes, properties, or fields, depending on the context. The technical term relationship has the regular, “English” meaning. The two-table database described in the preceding section is represented by the ERD shown in Figure 1.2.
Notice that we have made up names for all the fields that are now legal names with no internal blanks as opposed to descriptions. The line connecting the two boxes represents the relationship between the two tables. The markings indicate that each product—that is, each record in the catalog table—refers to exactly one category record. Put another way, a category can have many products. More than one product can be in a category. It, however, does not guarantee that each category has at least one product.
A slightly more complex database is shown in Figure 1.3. This database supports a quiz show application using three tables.
Figure 1.3: Entity relationship diagram for quiz show database.
The history table keeps records of the play of the game, with information on which player answered which question when and with what result. The history table serves as what is commonly called a “join table” to relate the question and the player entities. There is a one-to-many relationship between the question table and the history table and the player table and the history table. There can be none, one, or many entries in the history table for each question. Similarly, there can be none, one, or many entries in the history table for each player.
The process diagram in Figure 1.4 for the quiz show application reveals how the application is to function.
Figure 1.4: Process diagram for quiz show application.
Notice that there are two agents; that is, two types of users. Players play the game, with that process making use of three distinct data stores. These data stores correspond to the tables of the database, but that implementation detail is not critical in the process diagram. Editors input, delete, and modify questions.
The book will show you the inner workings of the quiz show application in PHP and ASP versions, and another application, a slightly more elaborate online store. Figure 1.5 shows a storyboard indicating the distinct files (scripts) we designed and wrote for the quiz show. You will learn about this application in Chapter 15, “Quiz Show.” For now, just look at the diagram as an example of representing an application made up of multiple files. The arrows represent one script calling another. One type of call is for handling a form, and another type is as the target of a hyperlink. Form handling is represented by thick arrows, and links by thin arrows. With this information, this diagram shows many things. First, there are eight scripts. One script, called opendbq, is an include/required file. This special file type will be explained later. The diagram also indicates the relationship among the files. For example, the diagram indicates that the choose category script invokes the ask question script to handle a form. The ask question script has a link back to the choose category script. The choose category script also has links from check answer and clear tables. There are links in both directions between the choose category script and the show scores script.
Figure 1.5: Storyboard for quiz show application.
We now look at simple code examples of PHP and ASP script.
An example of PHP coding:
<html> <head><title>first PHP </title></head> <body> <?php $today= Date('d-m-Y'); $now = Date('g:i'); print ("Hello World!<BR> Today is $today"); print ("<br>The time is $now"); ?> </body> </html>
The standard HTML boilerplate (we provide a review of HTML in the next chapter) is given in the PHP file as regular HTML. The <?php starts the PHP section. You can omit the PHP if the file has extension .php. The four lines within the delimiters do the following tasks:
Invoke the built-in Date function with the parameter specifying the format for the date. All variables in PHP start with the dollar sign.
Invoke the built-in Data function (again) with a different parameter to get the time.
Invoke the print function to output the string that is the argument of the function call to the HTML document. The PHP interpreter will use the value of the variable $today.
Invoke the print function again. In this case, the PHP interpreter will use the value of the variable $now.
The following ASP script produces a similar (although not identical) HTML document:
It is possible to write an even simpler “Hello, World” program. These programs do something on the server, namely calling the date functions, and it is doing something on the server that characterizes middleware.