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

PHP 5/MySQL Programming- P65 docx

5 287 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 244,52 KB

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

Nội dung

Now you learn how relational databases can be used to manage data.. Specifically, you learn: • How to start the MySQL executable • How to build basic databases • The essential data defin

Trang 1

g r

s o

l u

g in

e r

The first step is determining if an XML file has been sent through the $theXML parameter If not, a default value of main.xmlis defined This, of course, presumes that a copy of main.xml is available and properly formatted If the program is called with some other XML file as its parameter, that file is interpreted again

I then attempt to open the XML file If the simplexml_load_file command is unsuccessful, it returns the value FALSE The program reports this failure if it occurs If it does not fail, the program creates a page based on the parameters indicated in this file I expect a page with five parameters (top, css, title, menu, and content), but I could easily modify the program to accept as many parame-ters as you wish I ignored the titleparameter in this particular program version because I have the page title already stored in top.html

The program includes all the files indicated in the XML code, incorporating them

in CSS styles when appropriate

Summary

Content management systems can help automate your Web site’s creation CMS tools allow you to build powerful multipart Web documents, combining pages with a single style and layout You learned how to install and customize the pop-ular PHP-Nuke CMS You also learned how to build a very basic CMS of your own using GETparameters to customize your page You learned about XML and how to use the simpleXMLtools to parse any XML files you encounter Finally, you learned how to combine your newfound XML skills with CMS to build an XML-aware CMS

C H A L L E N G E S

1 Install and configure PHP-Nuke or another CMS on your system.

2 Create a custom theme by analyzing and modifying an existing theme.

3 Modify simpleCMS with your own layout, images, and banner files.

4 Create an editor that allows the user to build XML pages for XCMS.

5 Write an XCMS module that allows authorized users to add new content (a news or guest book, for example)

Trang 2

When you begin programming in PHP, you start with very simple variables. Soon you learned how to do more interesting things with arrays and

asso-ciative arrays You added the power of files to gain tremendous new skills Now you learn how relational databases can be used to manage data In this chapter you discover how to build a basic database and how to hook it up to your PHP programs Specifically, you learn:

• How to start the MySQL executable

• How to build basic databases

• The essential data definition SQL statements

• How to return a basic SQL query

• How to use phpMyAdmin to manage your databases

• How to incorporate databases into PHP programs

Using MySQL

to Create Databases

9

Trang 3

Introducing the Adventure

Generator Program

Databases are a serious tool but they can be fun, too The program shown in Fig-ures 9.1 through 9.4 shows how a database can be used to fuel an adventure game generator The adventure generator is a system that allows users to create and play simple multiple-choice adventures This style of game consists of several nodes Each node describes some sort of decision In each case, the user can choose from up to three options The user’s choice leads to a new decision If the user makes a sequence of correct choices, he wins the game

This program is interesting as a game, but the really exciting part is how the user can modify this game A user can use the same system to create and modify adventures Figure 9.3 shows the data behind the Enigma game Note that you can edit any node by clicking the appropriate button from this screen

If the user chooses to edit a segment, the page shown in Figure 9.4 appears

300

g r

s o

l u

g in

e r

FIGURE 9.1

The user can

choose an option.

I’m hopping onto

that sub

Trang 4

As you can see, the data structure is the most important element of this game.

You already know some ways to work with data, but this chapter introduces the

notion of relational database management systems (RDBMS) An RDBMS is a

sys-tem that helps programmers work with data The adventure generator program

uses a database to store and manipulate all the data

i n

FIGURE 9.2

Maybe the

warehouse would

have been a better

choice after all.

FIGURE 9.3

This page provides

information about

each segment in

the game, including

links to directly edit

each segment.

Trang 5

Using a Database Management System

Data is such an important part of modern programming that entire program-ming languages are devoted to manipulating databases The primary standard for database languages is Structured Query Language(SQL) SQL is a standardized language for creating databases, storing information in databases, and retrieving information from databases Special applications and programming environ-ments specialize in interpreting SQL data and acting on it

Often a programmer begins by creating a data structure in SQL, and then writes

a program in some other language (such as PHP) to allow access to that data The PHP program can then formulate data requests or updates, which are passed on

to the SQL interpreter This approach has a couple of advantages:

• Once you learn SQL, you can apply it easily to a new programming

language

• You can easily add multiple interfaces to an existing data set because many programming languages have ways to access an SQL interpreter Many relational database management systems are available, but the MySQL environment is especially well suited to working with PHP

302

g r

s o

l u

g in

e r

FIGURE 9.4

From this screen it

is possible to

change everything

about a node All

the nodes that have

been created so far

are available as

new locations.

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

TỪ KHÓA LIÊN QUAN