1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP 5/MySQL Programming- P82 pptx

5 214 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 207,04 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

This chapter ties together the PHP programming and data programming aspects to build a full-blown data-management system for the spy database.. Specifically, you learn how to: • Design a

Trang 1

This book begins by looking at HTML pages, which are essentially static documents It then reveals how to generate dynamic pages with the

powerful PHP language The last few chapters show how to use a database management system such as MySQL to build powerful data structures This chapter ties together the PHP programming and data programming aspects to build a full-blown data-management system for the spy database The system you learn can easily be expanded to any kind of data project you can think of, including e-commerce applications Specifically, you learn how to:

• Design a moderate-to-large data application

• Build a library of reusable data functions

• Optimize functions for use across data sets

• Include library files in your programs

There isn’t really much new PHP or MySQL code to learn in this chapter The focus is

on building a larger project with minimum effort.

Building a Three-Tiered

Data Application

Trang 2

g r

s o

l u

g in

e r

Introducing the SpyMaster Program

The SpyMasterprogram is a suite of PHP programs that allows access to the spy database created in chapter 11, “Data Normalization.” While the database cre-ated in that chapter is flexible and powerful, it is noteasy to use unless you know SQL Even if your users do understand SQL, you don’t want them to have direct control of a database, because too many things can go wrong

You need to build some sort of front-end application to the database In essence, this system has three levels

• The client computer handles communication with the user

• The database server (MySQL) manages the data

• The PHP program acts as interpreter between the client and database PHP provides the bridge between the client’s HTML language and the database’s SQL language

This kind of arrangement is frequently called a three-tier architecture As you examine the SpyMasterprogram throughout this chapter, you learn some of the advantages of this particular approach

Viewing the Main Screen

Start by looking at the program from the user’s point of view as shown in Figure 12.1 The main page has two sections The first is a series of data requests Each of these requests maps to a query

Viewing the Results of a Query

When the user selects a query and presses the Submit button, a screen like the one in Figure 12.2 appears

Trang 3

The queries are all prebuilt, which means the user cannot make a mistake by

typing in inappropriate SQL code It also limits the usefulness of the database

Fortunately, you can add new queries

385

i l

i o

FIGURE 12.1

The entry point to

the SpyMaster

database is clean

and simple.

FIGURE 12.2

The results of the

query are viewed in

an HTML table.

Trang 4

Viewing Table Data

The other part of the main screen (shown again in Figure 12.3) allows the user to directly manipulate data in the tables Since this is a more powerful (and thus dan-gerous) enterprise, access to this part of the system is controlled by a password

As an example, by selecting the agenttable I see a screen like Figure 12.4

g r

s o

l u

g in

e r

FIGURE 12.3

From the main

screen you can

also access the

table data with

a password.

FIGURE 12.4

The editTable

screen displays all

the information

in a table.

Trang 5

i l

i o

From this screen, the user can see all the data in the chosen table The page also

gives the user links to add, edit, or delete records from the table

Editing a Record

If the user chooses to edit a record, a screen similar to Figure 12.5 appears

The Edit Record page has some important features First, the user cannot directly

change the primary key If she could do so, it would have profound destabilizing

consequences on the database Also note the way the operationID field is

pre-sented The field itself is a primary key with an integer value, but it would be very

difficult for a user to directly manipulate the integer values Instead, the

pro-gram provides a drop-down list of operations When the user chooses from this

list, the appropriate numerical index is sent to the next page

Confirming the Record Update

When the user clicks the button, a new screen appears and announces the

suc-cessful update as in Figure 12.6

Deleting a Record

The user can also choose to delete a record from the Edit Table page This action

results in the basic screen shown in Figure 12.7

FIGURE 12.5

The user is editing

a record in the

agent table.

Ngày đăng: 07/07/2014, 02:20