文件名称:
PHP and MySQL by Example.pdf
开发工具:
文件大小: 21mb
下载次数: 0
上传时间: 2019-08-18
详细说明:Over the past few years, students taking my Perl/CGI course continued to ask me when I would be graduating from CGI
to PHP, and whether I would offer a course or write a PHP “by Example” book. I didn’t really take the idea of a book
seriously until attending a PHP/MySQL class here in San FranciscoPreface
Over the past few years, students taking my Perl/cGi course continued to ask me when i would be graduating from CGI
to PhP, and whether i would offer a course or write a php""by example"book i didn 't really take the idea of a book
seriously until attending a PhP My SQL class here in San Francisco a few years ago, where I met Marko Gargenta, who
was the teacher of that class and the inspiration for this book we had lunch together and I mentioned to him that the
girl sitting next to me in the class was a web designer, with little programming experience. She was concerned that she
couldnt keep up with the class and wondered if i knew where she could find a book that explained PHP for designers
not just programmers. Marko had heard similar concerns from his students. We talked about how to address this issue
and from that conversation, the seeds were sown for PHP and mysQl by example
Although, theoretically, the Web designer/developer should need no PhP programming experience to change the
database, and so on, they do not always work in isolation. For example, suppose a page is designed so that when the?
content of a page, and the programmer should be concerned only with the logic, such as calculations, sending data to
user enters bank information in an HTML form, a PHP program, after doing some calculations, finds that there are
insufficient funds, and sends back an error in a bold red font. In such a case, PhP and hTML are integrated-one to
calculate and produce the error message, the other to display it in a bold red font. Keeping the design and program logic
separated may be the goal, but it is often impossible with the complexities of todays Web development
And then there is the issue of the database management system. Where does the processed data get stored? Who designs
the database and its tables? Who administers it? How does the information get from the Web page, to the PhP program
and then to the database? Enter MysQL. Is this yet another world in isolation?
Since my first meeting with Marko, I was challenged to bring these technologies together. When Prentice Hall agreed to
publish our book, the learning curve was steep, and after the initial draft was done, I began teaching"An Introduction to
PHP and MySQL Programming from the PDF version of that first draft. I noticed that more Web designers were
signing up than programmers, and they came in with trepidation that it would be way over their heads. But with the
real-world examples and labs we provided, they started to enjoy feelings of success on the first morning. It was
wonderful to witness both designers and programmers sharing their experiences without the artificial boundary that has
kept them isolated from each other in the workplace
The mission of PHP and MysQL by Example is to create a gentle yet thorough introduction to the shared power of PHP
and MySQL, to make static HTML pages dynamic. The labs and exercises have been tested by myself, Marko, and our
students. I think you will find this "by Example book a helpful and complete guide, no matter what side of the web
site you support, or even if you are just starting your own
Acknowledgments
Many people helped with the creation of this book. I'd like to thank mark l. Taub, my longtime editor at Prentice Hall
Vanessa Moore, the most gifted compositor on the planet; and Julie Nahil, a great production editor Matthew
Leingang, Sander van Zoest, David Mercer, and Jason Wertz provided extremely helpful manuscript reviews. Any
remaining mistakes are my own
Id also like to thank the students in my classes who provided valuable input for the labs. These include rita Mccue
Sanjay shahri, Ryan Belcher, Debra Anderson, and Catherine nguyen
The fantastic illustrations in the book were created by elizabeth Staechelin and Daniel Staechelin And many thanks to
the artists who provided artwork for the art gallery example. They are Elliott Easterling, Laura blair, Stuart Sheldon
and Todd brown
Errata and solutions to the labs can be found on the book 's web site at
www.prenhallprofessional.com/title/0131875086.TheNorthwinddatabasescriptusedinthechapterscanbefoundat
http://marakana.com/download!sql/northwind.sql
Ellie Quigley
San francisco california
September 2006
Chapter 1 Introduction
1.1. From Static to Dynamic Web Sites
1.1.1. Static Web sites
The dream behind the Web is a common information space in which we communicate by sharing information
Tim berners-Lee
Sir tim berners-Lee
When Tim Berners-Lee invented the world wide web in 1989, he unleashed an information revolution unparalleled
since Gutenberg invented the printing press in the fifteenth century. Within less than 10 years the world as we knew it
would be forever changed by his creation
A 25-year-old computer consultant, Tim Berners-Lee started his initial work on the Web while working at Cern,a
physics lab in Geneva, Switzerland. cerN was a huge scientific research center consisting of thousands of researchers
and hundreds of systems. Berners-Lee first attempted to organize the documents on his hard drive by linking them
together, which culminated in a hypertext language making it possible to link and distribute related documents, not only
on his computer, but on networks of computers. His system kept track of the researchers, their projects and papers, the
software they were using their computers, and so on. To retrieve and send documents, he developed a simple protocol
Http(The Hypertext trAnsfer Protocol), and created Html(tHe Hypertext Markup Language)to describe the layout
for the text in the documents. The early Web was like an online library, documents connected by links, where the high
energy scientific community could freely read and access information throughout their company and eventually around
the world
The original Web was funded by the government, limited to research and education. The Web sites were made up of a
collection of documents written in the HTML language. The pages were text based, simple, and static. Every time the
user reloaded a page in his or her browser, it looked exactly the same. It consisted of hTMl text, images, and links. It
was not the complex commercial Web we know today where you can do anything from online shopping, to trading
stocks, booking vacations, or finding a mate. Static Web pages were useful for sending and retrieving reports, pictures
and articles, but they couldnt manage data that changed, remember users names and preferences, instantly create
customized output from a database, or embed streaming video into a page on the fly. As the Web grew and became a
virtual shopping mall, competitors needed Web sites that would lure in potential buyers and traders with an interactive
and exciting experience, quick response time, and on-the-fly feedback. They needed dynamic Web sites
1. 1.2. Dvnamic Web sites
a dynamic web site is one with content that is regenerated every time a user visits or reloads the site. although it can
be as simple as displaying the current date and time, in most cases it requires the use of a database, which contains the
site's information, and a scripting language that can retrieve the information from the database. Google and Yahoo! are
examples of dynamic sites, search engines that create customized pages based on a key word or phrase you type. The
resulting page is created on the fly, customized just for you, based on your request. Farms of powerful computers all
over the world are constantly taking such requests and processing therm In the early days of the Web, processing was
done through the Common Gateway Interface, called CGl, a server-side technology that allowed web developers to
create dynanic sites. Most CGI scripts were written in Perl. A browser would send information from an HTML Web
external program called a CGi script or helper program. Although any programming language could be used, the mo
page, such as information from a fillout form, to the server for processing. The server then would create a gateway to
popular language for CGI was Perl. The Perl script would then parse the data, generate HTML based on certain
conditions, Send an e-mail, open a file or database, and send in formation through the gateway back to the server, where
it then was relayed onto the browser. (See the top portion of Figure 1. 1
Figure 1.. The process of creating dynamic Web sites
Http
Server
Per
rowser
CGI
Database
Scri
Server
Br
owser
Database
PHP
Although the basic underlying process of creating dynamic Web sites hasnt changed, new languages have evolved,
making the process much simpler by allowing the processing to be embedded right in the server PhP is such a
language. A PHP script can be embedded right in the Web page. It can generate HTML and images on the fly, retrieve
up-to-date information from a file or database, encrypt data, remember user preferences, and so on. It executes PHP
instructions and inserts the results right back into the Web page before the server sends the page back to the browser,
thus making the page truly dynamic. (See the bottom portion of Figure 1. 1.
I To imply that Perl is outdated is not the intention here. Perl has Mason and mod_perl to allow Perl and html to be
embedded in the apache server
Web sites often handle huge amounts of information. a database management system is essential for storing, retrieving
and updating that information. MySQL, the worlds most popular open source database, has become the choice for
applications that interact with database-enabled Web sites. PHP and My SQL, working together, form a marriage of two
powerful technologies used to produce dynamic Web pages. This book will show you how that marriage works
13. What Is Open Source?
Free software "is a matter of liberty, not price. To understand the concept you should think of"free"as in "free
speech, not as in"free beer.
TheFreeSoftwareFoundationhttp:/www.gnu.orgiphilosophy/free-sw.html
PHP and My sQL represent the latest generation of open source applications. What does that mean? In the beginning
Berners-Lee envisioned making information freely accessible to everyone. As the Web evolved this idea of"free"took
on different meanings for different groups. But however" free"is defined, it is safe to say that proprietary (privately
ownedandcontrolledsoftwareisnotfree(seEhttp://www.gnu.org/philosophy/free-software-for-
freedom html#relationship. The Open Source movement is designed to make software source code freely available
with limited restrictions. According to the open source initiative
2 Microsoft Windows, Adobe Photoshop and Win Zip are examples of proprietary software
The basic idea behind open source is very simple: When programmers can read, redistribute, and modify the source
code for a piece of software, the software evolves. People improve it, people adapt it, people fix bugs. And this can
happen at a speed that, if one is used to the slow pace of conventional software development, seems astonishing
Forthecompletediscussionseehttp:/www.opensource.org/docs/definition.phy
PHP and My SQL are both open source. Simply stated you can download and use these applications without a credit
card or a free trial period
1.2. About PHP
Rasmus lerdorf
LatLy
So what is PHP? PHP is a simple, fast, portable scripting language well suited for development of database-enabled
Web sites. It was developed in 1995 and is currently powering tens of millions of Web sites world wide. The
predecessor to PHP was PHP/FI, Personal Home page/Forms Interpreter, developed by Rasmus Lerdorf in 1995 to help
him track the number of visitors accessing his online resume. It was basically a set of Perl/CGI scripts later rewritten by
Lerdorf in the C language and open-sourced; that is, made freely available. PHP was very Perl-like in sytnax, but
whereas Perl is an all-purpose, jack-of-all-trades scripting language, PHP was designed specifically to master the Web
PHP instructions can be embedded with HTML right in the Web page so that whenever the page is loaded, PHP can
execute its code. PHP made processing forms easier by providing automatic interpretation of form variables. It allowed
for interaction with databases. It enabled users to create simple dynamic web sites. The toolset Rasmus Lerdorf
developed was so popular that in 1997, PHP/FI 2.0 was released. Due to the popularity of this new release, Lerdorf was
soon joined by a core group of developers, who continued to provide improvements and enhancements to the new
language. By this time, there where thousands of users and approximately 50,000 Web sites running PHP/FI pages
Zeev Suraski and Andi gutmans, two students attending Technion-Israel Institute of Technology, needed a language for
their university e-commerce project. They chose PHP/Fl for their project. Dissatisfied with its limitations and bugs
they put their project aside, and rewrote PHP almost from scratch. PHP 3.0 was a significant departure from the
previous code base. The new language supported add-on modules and had a much more consistent syntax. At this time
the meaning of the acronym changed as well. PHP now stands for PHP: Hypertext Preprocessor. PHP3.0 was released
in 1 998 and is the closest version to php today
By May 2000, PHP 4 was released. The core of PHP 4 was entirely rewritten to improve the performance of complex
Web applications and improve modularity of the platform Zeev Suraski and Andi Gutmans the authors of Php3
introduced a new
parsing engine, called the Zend engine /31 which is the scripting language that powers PHP today
Because of their internationally recognized authority suraski and gutmans founded Zend Technologies, the PhP
company, and their contributions to PhP have been a major reason for its explosive worldwide growth. See
www.zend
ISI The term Zend is a portmanteau, a word created by combining the letters in their first names: Zeev and Andrew
Ⅴ ersion4 offered
Application pro
pr
ers to write modules for
PHP, modules that would extend its functionality, modules that allowed PHP 4 to support most of the available
databases and Web servers available. With this release, Php became a serious programming language and platform for
developing and deploying complex web applications
The latest incarnation of PHP was released in July 2004. PHP 5 added a whole new object-oriented model to the
language. The new model is based on Zend Engine 2 and greatly improves PHP performance and capabilities. Most of
the functionality is backward compatible, allowing programs written in older versions to continue working
According to a Netcraft survey, as of October 2005, 23, 299, 550 domains and 1, 290, 179 IP addresses endorse PHP. See
http://www.php.net/usage.php
21. Where to get phP and documentation
You can get the latest distribution of PHP for Apache and Microsoft servers at the official Web site for PHP, php.net
(see Figure 1. 2). This Web site is also an excellent up-to-date resource for PHP documentation. You can find a
particular function, for example, by typing the search string into the top right corner of the page, and the result returned
will be very close to what you were looking for, including links to other functions that perform a similar task. Most of
the official documentation pages are annotated with the comments fron other users as well as any bugs or revision
changes(see Figure 1.3)
Figure 1. 2. The PHP home page
EPHP: Hypertext Preprocessor Mozilla Firefox
FleEdtyiew Go Bookmarks Took Help
,·③价
Itp: ww, php, net
0a〖
1 Customize Links D Free Hotmail RealPlayer L windows Marketplace D Windows Meda L Windo
np net sites links my php.net
search for
inthe funcion list
What is pHP?
PHP 4.4.1 Released
This mirror sponsored
PHP is a widely-used
general-purpose scripting
2200FHF44.1sn
language that is especially
available for download this
suited for Web development: version is a maintenance
点Eu
and can be embedded into
elease that contains
TELK
HTML: If you are new to
numerous bug fixes, incuding
THE PLACE FOR EYERYTHINd
I-EIWEEHdHAcI
PHP and want to get some a number of security fixes
idea of how it works, try the related to the overwriting of Now Featuring
introductory tutorial. After: the GLOBALS array. All users
that, check out the online of PHP 4.3 and 44 are
wnw,Methos tingtaik, cam
manual, and the example
archive sites and some of
encouraged to upgrade to:
this version.
the other resources
Upcoming Events
available in the links
The full list of changes in PHP i addl
section
4,4.1 is avalable in the Php 4
Ever wondered how popular, Changelog.
November
PHPi当? see the Netcraft
Survey
PHP
User Group Events
Conference
a
Figure 13. PhP download page
I PHP: Donlands Mori a firman
Fle Edt Wew fo Rook marks Tosks Help
OG,
h.
dw融dm配n的h地pnbp|自 fY DhA
rearch far aubry
in the functon lint
Binaries for other
PHP5,1。1
systcms
We do not diatomite
Complete Source Code
UNIX/Unux binaries. Most
Linux distributions coma
PHP 5.1 1(tar bz2) [5.005Kb]-28 NOV 2005
with PH2 these days, so if
mds:77c90ae1B2d181901c390b844153c7
you do nat want to campile
your Own, go to your
FHP511t2[,66Bkb]-28Now2005
distirhution's download site
mds:ed3099828282e66c6cadd8d979d739
Binanas availabls an
external server:
Windows Binaries
As400
a FHP 5.1.1 zip package [6. 620Kb]-28 NOY 2005
Mac 05 x
mds:75756005e1b95be75489b32cd21c
NN创M的twa鱼
os/2
Collection of FECL modules for PHP 5.1-1 [1, 599Kb]-28 Now 2005
mds: 771c1aaf254fa4118385a5e19b50092f
SGRS.
PHP 5.1 1 installer [2,50/Kb]-28 NoY 2005
solaris(p点Rc,INTE
CGl ony, packaged as windows installer to install and configure FHP, and
older versions of PHP
automatically configure ll, Pws and xitami, with manual configuration for
other servers. N B. no external extensions induded
See our releases page for
mds:b453455e2ba2221848902294176991c
older PHP versions.
We have a PHP 5/Zend Engine 2 page explaining the language level changes
other Downloads
introduced in PHP S, The FHP5 Changel ag deta s all the other changes.
1.3. About MySOL
Monty widenius
Today many organizations face the double threat of increasing volumes of data and transactions coinciding with a need
to reduce spending. Many such organizations are migrating to open source database management systems to keep costs
down and minimize change to their existing systems. The world's most popular of these open source database systems
(it's free to download, use, and modify)is My SQL. It is distributed and supported by MySQL AB, a Swedish
commercial company founded by the original developers, David Axmark and Michael"Monty"Widenius, who wrote
MySQL in 1995. MySQL has its roots in mSQL or mini SQL, a lightweight database developed at Bond University in
Australia, to provide fast access to stored data with low menory requirenents. Its sy mbol is a dolphin called"Sakila
representing"speed, power, precision and good nature of the My SQl database and community. 4)
14lMontyWidenius,MysqlfounderandCto,fromanewsreleasehltP:/iwww.nysgl.com/news-and-
events/news/article 116.html
1.3.1. Where to Get mysQL and Documentation
MySQL is installed on Inore than 6 million servers worldwide to power many high-volume and business-critical Web
sitesSeehttp:/www.nlysql.coim/company/factsheet.html.MysqlwascreatedbyMySqlAbandisavailablefor
downloadfrointheirWebsiteathttp:/www.nysql.corm,whereyoucanalsofindthelatestinfornationaboutMysql
software and MySQL AB (see Figures 1. 4 and 1.5)
Figure 1. 4. The MysQL home page.
EMySQL AB: The World's Most Popular Open Source Database -Mozilla Firefox
品e世ttss息 marks Tools秒
Noao〖Q
Custom links所 ee Homad Rea pwer Widows Marbebplce Windows Media□ WindS
Te Mor& mos poplar open source anatase
Login f Reister
aFn
Msn ulnHadevGo
Farters
On ne Shop
Products Training Consulting support oEM News Events Customers why MySQL? How to Buy
anren
News
MySQL Proe
MysQL 5. 0 Downloaded one
MIlion times in first tree
is Herel A
Data Diction
M创L5,0Aale
Poduction use
anc more
1s* MysqL Northern
Europe Customer Coference
The most important release gver
Download MySQL 5.01 Read the
Articles
Datasheet n
m Using BIRT To Report On
Eugzilla in MySPL
White Papers
eb seminars
MysQL Training
nmgM忌Ma日
MYSQL Network and
se5500
Synchronization Manager
InsUl NtROL5.自
MYSQL5,D
Ms。L5for
Downloads
MEDL 4 Plugable
Register How i
Deve opers More
MSEL DH#EA
MysQL 5, D PLUggable
M SCL Tools
MyseL 5.0 stored
sorage
Nor 28- London
ML亡
Pinfarluirt当
Register How睡
Dec 5 wash noton Dr
Jan 23: koin
Documentation n
Mys叫L50 Triggers助
Fme Unsung Heroes or
MY5QL50
MhrsoL 5dior DBAS
White Papers Nh
MySOL乐vws种
Register Not睡
More a电sm
血鱼F下血
Figure 1.5. The My SQL Documentation page.
独世wwI
q·中·母8即收小
IEVELOFFR FO HF
LnPR的sfr
MUSQL MY50Lcom
:30L Network
orvelaper?曰n
Partners
Online shap
Downloads Documentation Forums Lists Bugs Events User Groups Guilds Blogs support Resources Books FAQ
MySOL Documerabon
Overview MysCL Reference Laus 323 404.1 5.0 5.1 MacO DoouTertwten
The MEaL Referente Manual covera most of the areas ofMhBOL use This manual is far
bosh MyoL Communit Edtion and M oL Netork日 wi wanaaring数图容种到的m
the manual, You can ga support by purchaing MBOL Nobwoak, which prouder
Get a head start
comgeeherrs me suppon and semiteS MYSoL Netaur also provides a temnnenensme
2)w的
knowed ae Base Frary that includes hundreds oftechnical articles reson uncut
problems an popular camas topics such as peroRmance, replication, and mn atio
MuSL,的swB
Iymmn2?
Leaf fr cure ahou The oimerenas beTween LhaDL commun Eui n and M3DL NRM0tk
You can also find help by ws ting the MaOL Forums or by browsing our main ial
Related pages
FERN
Dui
183.2. Features of MySQL
My SQL is a relational database management system. Whether you're involved with a Web site that processes millions
of requests a day like e Bay or Yahoo! or a smaller site such as your own online shop or training course, the data must
be stored in an organized and structured way for easy access and processing. This is handled by a database management
system such as MysQL where the data is stored in tables rather than in a flat file
MySQL uses the client/server model; that is, a database server MysQL) that serves(communicates) with multiple
clients(application programs), where the clients may or may not be on the same computer. It also supports SQL, the
structured query language, a standardized language used by most modern databases for working with data and
administering the database
MySQL Software is open source. As discussed carlier in this chapter, open source means that it is possible for anyone to
download mysQl from the Internet, and use and modify the software without paying anything. The mysQL software
usestheGpl(GnuGeneralPublicLicense),http://www.fsf.org/licenses,todefinewhatyoumayandmaynotdowith
the software in different situations. If you need to use MySQL code in a commercial application, you can buy a
commercially licensed version. See the My SQL Licensing Overview for more information
(http://www.mysql.com/company/legal/licensingl)
The My SQL Database Server is very fast, reliable, and easy to use. MySQL Server was originally developed to handle
large databases much faster than existing solutions and has been successfully used in highly demanding production
environments for several years. Its connectivity, speed, and security make My sQL Server highly suited for accessing
data bases on the internet
MySQL Serves as a back end for all kinds of information such as e-mail, Web images and content, games, log files, and
so on. The server can be embedded in applications such as cell phones, electronic devices, public kiosks, and more
1.3.3. How to Install MySQL and PHP
Appendix e of this book contains instructions on the installation procedures for Windows, UNIX, Macintosh, and so
on. The source code for PhP and MySQL can also be found on the Cd included in the back cover of this book
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.