Tải bản đầy đủ (.pdf) (5 trang)

PHP 5/MySQL Programming- P9 pps

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (147.19 KB, 5 trang )

18
P
H
P
5
/M
y
S
Q
L
P
r
o
g
r
a
m
m
i
n
g
f
o
r
t
h
e
A
b
s
o


l
u
t
e
B
e
g
i
n
n
e
r
You can determine whether PHP added support for MySQL by looking again
at the results of the phpInfo() function. If exposing the php_mysql.dll
extension didn’t work on its own, you may have to locate the libmysql.dll file
and move it to the C:\Windows directory.
I also added support for two graphics libraries that I occasionally use. The gd2
library allows me to build and modify graphics, and ming allows me to create
Flash movies. Don’t worry about exposing these files until you’re comfortable
with basic PHP programming. However, when you’re ready, it’s really nice to
know that you can easily add to the PHP features by supporting new modules.
Some of the documentation that came with version 5.0 of PHP indicated that
MySQL support is built in and doesn’t need to be added through the configuration
file. (In fact, this information is inside the configuration file as a comment.)
When I ran phpInfo(), I found that MySQL support was
not
built in, so I added it
through the extension command. The sad truth is you can’t always trust the docu-
mentation.
Take a look at the extension_dir variable in php.ini to see where PHP expects to

find all your extension files. Any
.dll file in that directory can be an extension.
You can also download new extensions and install them when you are ready to
expand PHP’s capabilities.
Because of space limitations, I was unable to include information on graphics pro-
gramming in PHP in this book. However, you can always check on my PHP Web
site (:18011/n342) for examples and tutorials on these
techniques.
Creating the Tip of the Day Program
Way back at the beginning of this chapter, I promised that you would be able to
write the featured Tip of the Day program. This program requires HTML, CSS, and
one line of PHP code. The code shows a reasonably basic page:
<html>
<head>
<title>Tip of the day</title>
</head>
<body>
<center>
TRICK
TRAP
TRICK
<h1>Tip of the day</h1>
<div style = “border-color:green; border-style:groove; border-width:2px”>
<?
readfile(“tips.txt”);
?>
</div>
</center>
</body>
</html>

The page is basic HTML. It contains one div element with a custom style setting
up a border around the day’s tip. Inside the
div element, I added PHP code with
the
<? and ?> devices. This code calls one PHP function called readFile(). The
readFile() command takes as an argument the name of some file. It reads that
file’s contents and displays them on the page as if it were HTML. As soon as that
line of code stops executing (the text in the
tips.txt file has been printed to the
Web browser), the
?> symbol indicates that the PHP coding is finished and the
rest of the page will be typical HTML.
Summary
You’ve already come a very long way. You’ve learned or reviewed all the main
HTML objects. You installed a Web server on your computer. You added PHP. You
changed the Apache configuration to recognize PHP. You saw how PHP code can
be integrated into an HTML document. You learned how to change the configu-
ration file for PHP to incorporate various extensions. Finally, you created your
first page, which includes all these elements. You should be proud of your
efforts already. In the next chapter you more fully explore the relationship
between PHP and HTML and learn how to use variables and input to make your
pages do interesting things.
19
C
h
a
p
t
e
r

1
E
x
p
l
o
r
i
n
g
t
h
e
P
H
P
E
n
v
i
r
o
n
m
e
n
t
20
P
H

P
5
/M
y
S
Q
L
P
r
o
g
r
a
m
m
i
n
g
f
o
r
t
h
e
A
b
s
o
l
u

t
e
B
e
g
i
n
n
e
r
CHALLENGES
1. Create a Web-based version of your resume, incorporating headings, lists,
and varying text styles.
2. Modify one of your existing pages so it incorporates CSS styles.
3. Install a practice configuration of Apache, PHP, and MySQL (or some other
package).
4. Build a page that calls the phpInfo() command and run it from your Web
server. Ensure that you have a reasonably recent version of PHP installed on
the server.
I
n chapter 1, “Exploring the PHP Environment,” you learn the foundations of
all PHP programming. If you have your environment installed, you’re ready to
write some PHP programs. Computer programs are ultimately about data.
In this chapter you begin looking at the way programs store and manipulate data in
variables. Specifically, you learn how to:
• Create a variable in PHP
• Recognize the main types of variables
• Name variables appropriately
• Output the values of variables in your scripts
• Perform basic operations on variables

• Read variables from an HTML form
U
s
i
n
g
V
a
r
i
a
b
l
e
s
a
n
d
I
n
p
u
t
2
CHAPTER
Introducing the Story Program
By the end of this chapter you’ll be able to write the program, called Story, featured
in Figures 2.1 and 2.2.
The program asks the user to enter some values into an HTML form and then uses
those values to build a custom version of a classic nursery rhyme. The

Story
program works like most server-side programs. It has two distinctive parts: a form
for user input, and a PHP program to read the input and produce some type of
feedback. First, the user enters information into a plain HTML form and hits the
submit button. The PHP program doesn’t execute until after the user has submitted
a form. The program takes the information from the form and does something
to it. Usually, the PHP program returns an HTML page to the user.
22
P
H
P
5
/M
y
S
Q
L
P
r
o
g
r
a
m
m
i
n
g
f
o

r
t
h
e
A
b
s
o
l
u
t
e
B
e
g
i
n
n
e
r
FIGURE 2.1
The program
begins by asking
the user to enter
some information.

Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×