•
•
•
•
•
•
TableofContents
Index
Reviews
ReaderReviews
Errata
Academic
WebDatabaseApplicationwithPHPand
MySQL,2ndEdition
ByDavidLane,HughE.Williams
Publisher :O'Reilly
PubDate :May2004
ISBN :0-596-00543-1
Pages :816
Thisneweditionhasbeenredesignedaround
therichofferingsofPEAR.Severalofthese,
includingtheTemplatepackageandthe
database-independentqueryAPI,arefully
integratedintoexamplesandthoroughly
describedinthetext.Inaddition,througha
complexsampleapplication--Hughand
Dave'sWineStore--alltheimportant
techniquesofdynamiccontentare
introduced.Gooddesignisemphasized,such
asdividinglogicfrompresentation.Thebook
introducesPHP5andMySQL4.1features,
whileprovidingtechniquesthatcanbeused
onolderversionsofthesoftwarethatarestill
inwidespreaduse.
•
•
•
•
•
•
TableofContents
Index
Reviews
ReaderReviews
Errata
Academic
WebDatabaseApplicationwithPHPand
MySQL,2ndEdition
ByDavidLane,HughE.Williams
Publisher :O'Reilly
PubDate :May2004
ISBN :0-596-00543-1
Pages :816
Copyright
Preface
WhatThisBookIsAbout
WhatYouNeedtoKnow
HowThisBookIsOrganized
ConventionsUsedinThisBook
HowtoContactUs
Acknowledgments
HowtoUseThisBook
UsingCodeExamples
WebSiteandCodeExamples
Chapter1.DatabaseApplicationsandtheWeb
Section1.1.TheWeb
Section1.2.Three-TierArchitectures
Chapter2.ThePHPScriptingLanguage
Section2.1.IntroducingPHP
Section2.2.ConditionsandBranches
Section2.3.Loops
Section2.5.WorkingwithTypes
Section2.7.AWorkingExample
Section2.4.Functions
Section2.6.User-DefinedFunctions
Chapter3.Arrays,Strings,andAdvancedDataManipulationinPHP
Section3.1.Arrays
Section3.2.Strings
Section3.3.RegularExpressions
Section3.5.IntegersandFloats
Section3.4.DatesandTimes
Chapter4.IntroductiontoObject-OrientedProgrammingwithPHP5
Section4.1.ClassesandObjects
Section4.2.Inheritance
Section4.3.ThrowingandCatchingExceptions
Chapter5.SQLandMySQL
Section5.1.DatabaseBasics
Section5.2.MySQLCommandInterpreter
Section5.3.ManagingDatabasesandTables
Section5.5.QueryingwithSQLSELECT
Section5.7.CaseStudy:AddingaNewWine
Section5.4.Inserting,Updating,andDeletingData
Section5.6.JoinQueries
Chapter6.QueryingWebDatabases
Section6.1.QueryingaMySQLDatabaseUsingPHP
Section6.2.ProcessingUserInput
Section6.3.MySQLFunctionReference
Chapter7.PEAR
Section7.1.Overview
Section7.2.CoreComponents
Section7.3.Packages
Chapter8.WritingtoWebDatabases
Section8.1.DatabaseInserts,Updates,andDeletes
Section8.2.IssuesinWritingDatatoDatabases
Chapter9.ValidationwithPHPandJavaScript
Section9.1.ValidationandErrorReportingPrinciples
Section9.3.JavaScriptandClient-SideValidation
Section9.2.Server-SideValidationwithPHP
Chapter10.Sessions
Section10.1.IntroducingSessionManagement
Section10.2.PHPSessionManagement
Section10.3.CaseStudy:UsingSessionsinValidation
Section10.5.PHPSessionAPIandConfiguration
Section10.4.WhentoUseSessions
Chapter11.AuthenticationandSecurity
Section11.1.HTTPAuthentication
Section11.2.HTTPAuthenticationwithPHP
Section11.3.Form-BasedAuthentication
Section11.4.ProtectingDataontheWeb
Chapter12.Errors,Debugging,andDeployment
Section12.1.Errors
Section12.2.CommonProgrammingErrors
Section12.3.CustomErrorHandlers
Chapter13.Reporting
Section13.1.CreatingaReport
Section13.2.ProducingPDF
Section13.3.PDF-PHPReference
Chapter14.AdvancedFeaturesofObject-OrientedProgramminginPHP5
Section14.1.WorkingwithClassHierarchies
Section14.2.ClassTypeHints
Section14.3.AbstractClassesandInterfaces
Section14.4.FreightCalculatorExample
Chapter15.AdvancedSQL
Section15.1.ExploringwithSHOW
Section15.2.AdvancedQuerying
Section15.3.ManipulatingDataandDatabases
Section15.5.AutomatingQuerying
Section15.7.BackupandRecovery
Section15.9.TuningMySQL
Section15.4.Functions
Section15.6.TableTypes
Section15.8.ManagingUsersandPrivileges
Chapter16.HughandDave'sOnlineWines:ACaseStudy
Section16.1.FunctionalandSystemRequirements
Section16.3.CommonComponents
Section16.2.ApplicationOverview
Chapter17.ManagingCustomers
Section17.1.CodeOverview
Section17.2.CustomerValidation
Section17.3.TheCustomerForm
Chapter18.TheShoppingCart
Section18.1.CodeOverview
Section18.2.TheWinestoreHomePage
Section18.3.TheShoppingCartImplementation
Chapter19.OrderingandShippingattheOnlineWinestore
Section19.1.CodeOverview
Section19.2.CreditCardandShippingInstructions
Section19.3.FinalizingOrders
Section19.4.HTMLandEmailReceipts
Chapter20.SearchingandAuthenticationintheOnlineWinestore
Section20.1.CodeOverview
Section20.2.SearchingandBrowsing
Section20.3.Authentication
AppendixA.LinuxInstallationGuide
SectionA.1.FindingOutWhat'sInstalled
SectionA.2.InstallationOverview
SectionA.3.InstallingMySQL
SectionA.5.InstallingPHP
SectionA.4.InstallingApache
SectionA.6.What'sNeededforThisBook
AppendixB.MicrosoftWindowsInstallationGuide
SectionB.1.InstallationOverview
SectionB.2.InstallingwithEasyPHP
SectionB.3.What'sNeededforThisBook
AppendixC.MacOSXInstallationGuide
SectionC.1.GettingStarted
SectionC.2.InstallingMySQL
SectionC.3.SettingUpApacheandPHP
SectionC.4.What'sNeededforThisBook
AppendixD.WebProtocols
SectionD.1.NetworkBasics
SectionD.2.HypertextTransferProtocol
AppendixE.ModelingandDesigningRelationalDatabases
SectionE.1.TheRelationalModel
SectionE.2.Entity-RelationshipModeling
AppendixF.ManagingSessionsintheDatabaseTier
SectionF.1.UsingaDatabasetoKeepState
SectionF.2.PHPSessionManagement
SectionF.3.MySQLSessionStore
AppendixG.Resources
SectionG.1.ClientTierResources
SectionG.2.Middle-TierResources
SectionG.3.DatabaseTierResources
SectionG.4.SecurityandCryptographyResources
AppendixH.TheImprovedMySQLLibrary
SectionH.1.NewFeatures
SectionH.2.GettingStarted
SectionH.3.UsingtheNewFeatures
Colophon
Index
Copyright©2004,2002O'ReillyMedia,Inc.
PrintedintheUnitedStatesofAmerica.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reilly&Associatesbooksmaybepurchasedforeducational,
business,orsalespromotionaluse.Onlineeditionsarealso
availableformosttitles().Formore
information,contactourcorporate/institutionalsales
department:(800)998-9938or
NutshellHandbook,theNutshellHandbooklogo,andthe
O'ReillylogoareregisteredtrademarksofO'ReillyMedia,Inc.
WebDatabaseApplicationswithPHPandMySQL,theimageofa
platypus,andrelatedtradedressaretrademarksofO'Reilly
Media,Inc.
Manyofthedesignationsusedbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andO'ReillyMedia,Inc.
wasawareofatrademarkclaim,thedesignationshavebeen
printedincapsorinitialcaps.
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorsassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.
Preface
TherearelotsofPHPandMySQLresources.Sowhydidwe
decidetoaddthisbooktothemarket?Wemadethedecision
afterwestartedteachinggraduatestudentshowtoprogram
withPHPin1999.WefoundthatthePHPandMySQLmanuals,
aswellasmostbooks,trainpeopletouseparticulartools.But
almostnoresourcesexplainedtheprinciplesofprogramming
fortheWeb.WerealizedthatWebadministratorsand
programmersneededtoknowmorethanwhatPHPfunctionsto
useandhowtowriteSQLqueries.That'swherethisbook
comesin:it'llhelpyoulearnaboutwebdatabasedevelopment,
aswellasunderstandtheprinciples.
Thisbookexplainswhattodoandwhy,alongwithhowit'sdone
inPHPandMySQL.You'llfindinformationherethatyouwon't
findelsewhere.Hopefully,you'llusethisknowledgewith
whateverwebtoolsyouchooseinthefuture.Butyou'llalso
learnaboutthebreadthanddepthofPHPandMySQL.When
youfinishthisbook,you'llbeabletobuildanonlinestore,a
portal,oracontentmanagementsystem.
WhatThisBookIsAbout
Thisbookisfordeveloperswhowanttobuilddatabase
applicationsthatareintegratedwiththeWeb.Weshowyouthe
principlesandtechniquesfordevelopingsmall-tomedium-scale
webdatabaseapplicationsthatstore,manage,andretrieve
data.Thearchitecturewedescribeisasuccessfulframeworkfor
applicationsthatcanrunonmodesthardwareandprocess
morethanamillionhitsperday.
Weshowyouallofthecriticaltasksyouneedtoknowtobuild
successfulwebsoftware.Wecoverprogrammingfundamentals
fortheWeb.Weshowyoutheprinciplesandpracticeofworking
withdatabasesusingtheSQLquerylanguage.Weteachyou
abouttrackinguserswithsessions,securinganapplication,
separatingpresentationfromcode,writingdatabaseindependentcode,writingreports,addingerrorhandling,and
advancedobject-orientedanddatabasetopics.
Animportantfeatureofthisbookisourcasestudy,Hughand
Dave'sOnlineWines.It'sacompletebutfictionalonlineretail
storethatillustrateshowmostofthetechniquesdescribedin
thebookcanbeputtogethertobuildarealapplication.The
winestoreapplicationallowsuserstobrowseandsearcha
databaseofwines,additemstoashoppingcart,managetheir
membership,andpurchasewines.Ithasallthebasicsecurity,
user-tracking,anderror-handlingfeaturesofareal-world
application.Itfeaturesamedium-sizedatabasethatweusein
queryingexamplesthroughoutthebook.
WeuseOpenSourcesoftware,andweshowyouhowtouseit
onUnix-basedplatformssuchasLinuxandMacOSX,and
underMicrosoftWindows2000,2003,andXP.Ourdatabase
serverisMySQL,asystemknownforitssuitabilityto
applicationsthatrequirespeedbutlowresourceoverheads.Our
scriptinglanguageisPHP,whichisbestknownforitsfunction
librariesthatinteractwithmorethan15relationaldatabase
systems,thewebenvironment,andmanyotherservices.
Apacheisourwebserverofchoice,butmostotherwebservers
canbeusedsuccessfullywithMySQL,PHP,andthisbook.
WhatYouNeedtoKnow
Thisbookisaboutunderstandinganddevelopingapplication
logicthatbringsdatabasesandtheWebtogether.Weintroduce
databasesystemsoverthecourseofthebook,butour
discussionsdon'treplaceabookorclassdedicatedtorelational
databasetheory,orabookaboutaspecificrelationaldatabase
systemsuchasMySQL.Likewise,weassumeyou'realready
familiarwiththeWeb.Wedon'tdelvedeeplyintothethreekey
webprotocols,HTML,HTTP,andTCP/IP.
Youdon'tneedtoknowhowtoprogramtousethisbook,but
youdoneedtounderstandbasicHTML.OurintroductiontoPHP
doesn'tassumeyouarefamiliarwithwebscriptingorarea
programmer,butwedoassumeyouunderstandthebasicHTML
constructsandarefamiliarwiththepopularwebbrowsers.If
youcanuseatexteditortoauthoranHTMLdocumentthat
containsaformandatable,youhavesufficientHTMLskillsto
usethisbook.It'stheprinciplesofstructureinthemarkup
processthatareimportant,nottheattractivenessorusabilityof
thepresentationinthewebbrowser.
Youdon'tneedadetailedunderstandingofrelationaldatabases
tousethisbook,butaworkingknowledgeishelpful.We
presenttherelationaldatabasetheoryneededfordeveloping
simpleapplications,andwecovermanyotherbasicconcepts,
includinghowtotellwhenadatabaseisthemethodofchoiceto
storedata,thedatabasequerylanguageSQL,andacasestudy
thatmodelssystemrequirementsandconvertsthemodeltoa
databasedesign.Thisbookisn'tasubstituteforthemanygood
resourcesondatabasetheory.However,it'senoughtobegin
developingtheunderlyingdatabasesformanywebdatabase
applications.
WebrieflyintroducewebserversandnetworkinginChapter1
andprovideadditionalmaterialinAppendixB.Bothwebservers
andnetworkingareimportanttoawebdatabaseapplicationbut
aren'tthefocusofthisbook.Wepresentenoughinformationto
setupawebserverandtounderstandhowitfitsinthe
architectureofawebdatabaseapplication.Formany
applications,thisissufficient.Likewise,wepresentsufficient
detailsothatyouwillunderstandwhatnetworkingandnetwork
protocolissuesimpactwebdatabaseapplicationdesign.
HowThisBookIsOrganized
Thereare20chaptersand8appendixesinthisbook.Chapter1
toChapter5introducewebdatabaseapplications,PHP,MySQL,
andSQL:
Chapter1
Discussesthethree-tierarchitecturecommonlyusedinweb
databaseapplications,andhowdataisexchangedbetween
browsersandservers.ItintroducesPHPandMySQL,and
discusseswhenandwhydatabasesareusedontheWeb.
ThefeaturesofMySQL4.1andPHP5areintroduced.
Chapter2
IntroducesthePHPscriptinglanguage.Itcovers
programminginPHPanddiscussesthebasicprogramming
constructs,variables,types,functions,andtechniques.
Chapter3
ExplainstheintermediatelevelfeaturesofPHP,including
howtoworkwitharrays,strings,andtimesanddates.The
chapterisillustratedwithmanyshortexamplesthatshow
howeachtechniqueisusedinpractice.
Chapter4
Showsyouhowtousethebasicobject-oriented(OO)
featuresofPHP4andPHP5,andexplainswhyOO
programmingispopularandbecomingimportantinPHP.A
moreadvanceddiscussionofthenewOOfeaturesinPHP5
ispresentedinChapter14,butthischaptergivesyouall
theknowledgeyouneedtoworkwiththePEARpackages
thatarediscussedinChapter7.
Chapter5
IntroducesMySQLandhowtointeractwithitusingtheSQL
querylanguage.Thefocusofthechapterisanexampledrivensectiononquerying,andweillustrateitusing
examplesfromtheonlinewinestore'sdatabase.Wealso
introduceyoutothebasicsofcreating,deleting,and
updatingdataanddatabases.Amoreadvanceddiscussion
ofthefeaturesofMySQL4.1ispresentedinChapter15,
butthebasicsdiscussedinthischapteraresufficientfor
youtoworkwithallofthematerialuptoChapter13and
withtheonlinewinescasestudyinChapter17toChapter
20.
Chapter6toChapter11covertheprinciplesandpracticeof
developingwebdatabaseapplicationlogic.
Chapter6
IntroducesconnectingtoMySQLwithPHP.Weexplainthe
queryingprocessusedinmostinteractionswithMySQLand
presentexamplesthatusethePHPMySQLlibraryfunctions.
Weshowhowuserdataisencoded,sentinrequestsfroma
webbrowsertoawebserver,anddecodedforprocessingin
PHP.Wediscussthesecurityimplicationsinprocessinguser
dataandshowstepstosecureinteractivequerying
systems.Ourdiscussionsaresupportedbyshortexamples
thatshowyouhowtobuildsimplequerymodules.
Chapter7
DiscussesthePEARpackagerepository.Packagesare
sourcecodemodulesthatcanbeusedinyourcodeand
saveyoufromreinventingwidelyusedconcepts.PEAR
includesover100packagesfortasksasdiverseasdateand
timemanipulation,security,networking,anddatabase
access,andthischaptershowsyouhowtoinstalland
upgradethem.Thechapterfocusesonatemplates
packageausefultoolforseparatingHTMLfromcodeand
anotherfordatabaseabstraction.Bothpackagesareusedin
laterchapterstodeveloprobust,reusablecode.
Chapter8
Coverswritingdatatowebdatabases.Thereareseveral
reasonswhywritingdataisdifferentfromreadingitand
that'swhyitisn'tdiscussedinChapter6.Forexample,
reloadingorprintingapagefromawebbrowsercancause
datatobewrittentoadatabasemorethanonce.Multiple
usersaccessingthesamedatabaseintroducesother
problems,suchasdataunexpectedlybeingchangedbyone
userwhileit'sbeingreadbyanother.Wediscusshowto
solveproblemsrelatedtothenatureoftheWeband
multipleusers.Weillustratetheprincipleswithacasestudy
exampleofcollectingformdatafromauserandsavingitin
adatabase.
Chapter9
ThischapterisrelatedtoChapter8andpresentsthe
principlesandtechniquesforuserinputvalidation.Weshow
youtechniquessuchashowtovalidatedates,creditcard
numbers,andphonenumbers,andexplainhowtouse
theseinerror-checkingmodulesthatarescalableand
practicalforwebdatabaseapplications.Wealsointroduce
client-side,browser-basedJavaScriptandshowyouhowto
useitforcommontasksincludinguserinputvalidationin
thewebbrowser.
Chapter10
Coverstheprinciplesofaddingsessionmanagementtoweb
databaseapplications.Sessionmanagementallowsthe
interactionsbetweenauserandtheapplicationtobe
relatedsothat,forexample,ausercanloginandlogoutof
anapplicationandbeguidedthroughaseriesofstepsina
process.WeshowhowPHPmanagessessionsandillustrate
thetechniqueswithacasestudyofmanagingerror
feedbacktousers.Wealsodiscusswhenandwhennotto
usesessions,andhowtoconfigurePHP'ssessionhandlerso
it'ssecureandscalable.
Chapter11
Discusseswebsecurityandauthentication.Weshowhow
PHPcanbeusedforbasicauthentication,howdatabases
canbeusedtomanageusers,andwhyyoumightneedto
securecommunicationswiththesecuresocketslayer(SSL).
Thecasestudyisareusableauthenticationmodulewith
login,logout,andpasswordchangefeatures.
Chapter12toChapter15discusstasksandtechniquesyou'll
needwhenyou'rebuildingareal-worldapplicationordeploying
anapplicationtousers.
Chapter12
Errorhandlinganddebuggingarethefocusofthischapter.
WediscussthetypesoferrorsthatcanoccurinPHPand
showyouhowtoidentifythesourceofcommon
programmingerrorsthatcausetheseproblems.Wethen
showyouhowtowriteyourownerrorhandlerthatcanbe
integratedintoanapplication,andhowtotriggeryourown
errorswhenyouneedthem.Addingacustomerrorhandler
givesaprofessionalfinishtoanapplication.
Chapter13
DiscussesreportingfortheWebandwhatsolutionsworkin
PHP.ThefocusisproducingPDF(AdobePortableDocument
Format)reportsusingapopularPHPPDFlibrary,andwe
illustratethetechniqueswithseveralexamples.Thechapter
concludeswithafunctionreferencefortheclassweuse.
Chapter14
ThischaptershowsyoutheadvancedfeaturesofPHP5's
object-orientedprogrammingmodel.Weextendthe
discussioninChapter4,andshowyouhowtobuildand
reuseclasses,andhowtowritepowerfulOOapplications.
Thechapterconcludeswithacasestudythatshowshowall
ofthefeaturescanbeusedtogethertobuildacomplexand
powerfulclasshierarchy.
Chapter15
ThischaptershowsyoutheadvancedfeaturesofMySQL
4.1.ItextendsthediscussioninChapter5,andshowsyou
howtowritecomplexqueries,manipulatedataincomplex
ways,manageusers,andtuneyourdatabaseandMySQL
server.
Chapter16toChapter20presentandoutlinethewinestore
casestudythatshowshowmostofthetechniquesdiscussedin
thebookareputtogethertobuildanapplication.Theoutlines
aren'tcomprehensive:weassumeyou'vereadthebookand
understandtheprinciplesofdevelopingwebdatabase
applications.
Chapter16
Explainsthestructureofthewinestoreapplicationand
discusseshowtheprinciplesshowninearlierchaptersare
puttogethertobuildareal-worldapplicationthatisflexible,
robust,secure,andscalable.Italsoshowshowthescripts
worktogetherthroughfiguresandexplanations.Wealso
explainhowwe'vedevelopedclassesandfunctionsfor
general-purposetasks,andwelistthecodeofallofthe
reusablecomponents.
Chapter17
Presentsthecodeforcustomermanagementinthe
winestore.Welistthescriptsforcollecting,validating,and
modifyingcustomerdetails,andshowhownewaccounts
arecreated.
Chapter18
Presentsthecodefortheshoppingcartatthewinestore.
Theshoppingcartisstoredinadatabaseandeachuser's
cartistrackedusingthesessiontechniquesfromChapter
10.Thecartmoduleallowsausertoviewhercart,add
itemstothecart,updateitemquantities,deleteitems,and
emptythecart.
Chapter19
Presentsthecodefortheorderingandshippingmodulesof
thewinestore.Theorderingprocessshowshowcomplex
databaseprocessingisusedtoconvertashoppingcartinto
acustomerorder.Wealsoshowhowtovalidatecreditcard
details,sendanemailconfirmationoftheordertotheuser,
andshowtheconfirmationasanHTMLpage.
Chapter20
Concludesthewinestoreapplicationbypresentingtheuser
authenticationandsearchingmodules.Theuser
authenticationmoduleisalmostidenticaltotheonein
Chapter11.Thesearchingandbrowsingmoduleshowshow
todevelopacomponentthatpresentsalargenumberof
resultsinseparatepagesandhowtousepreviousandnext
functionalitytomovebetweenthepages.
Thereareeightappendixestothisbook:
AppendixA
AguidetoinstallingtheApachewebserver,PHP,and
MySQLonLinuxplatforms.Installationinstructionschange
assoftwarechangesovertime,sothelatestversionofthis
appendixcanbedownloadedat
/>
AppendixB
AguidetoinstallingtheApachewebserver,PHP,and
MySQLonMicrosoftWindowsplatforms.Installation
instructionschangeassoftwarechangesovertime,
thereforethelatestversionofthisappendixcanbe
downloadedat />
AppendixC
AguidetoinstallingtheApachewebserver,PHP,and
MySQLonMacOSXplatforms.Installationinstructions
changeassoftwarechangesovertime,sothelatestversion
ofthisappendixcanbedownloadedat
/>
AppendixD
DescribestheworkingsoftheWebandexplainshowthe
HTTPprotocolisusedtotransferdatabetweenbrowsers
andservers.
AppendixE
Containsacasestudythatmodelsthesystemrequirements
forthewinestoreusingentity-relationshipdatabase
modeling.Itshowshowthismodelcanbeconvertedtoa
design.ItalsodetailstheSQLstatementsusedtocreate
thewinestoredatabase.
AppendixF
AnextensionofChapter10,thisappendixshowshowthe
defaultPHPmethodforsessionhandling(whichusesdisk
files)canbemovedintoadatabase.
AppendixG
Listsusefulresources,includingwebsitesandbooks
containingmoreinformationonthetopicspresented
throughoutthisbook.
AppendixH
AguidetoPHP'snewimprovedMySQLlibrary,andhowit
makesuseofthenewfeaturesofMySQL4.1.
HowtoUseThisBook
Thisbookisdesignedasatutorial-styleintroductiontoweb
databaseapplications.Tobegin,readChapter1foranoverview
ofthearchitectureandtoolsthatareusedinthisbook.
Ifyouhaven'tinstalledtheApachewebserver,thePHP
scriptingengine,ortheMySQLdatabasemanagementsystem
(oryou'renotsureyou'vegotthelatestsoftware),thenfollow
theinstructionsinAppendixA,AppendixB,orAppendixC,
dependingontheplatformyouareusing.Theyalsoshowhow
theexamplesusedinthisbookcanbedownloadedandinstalled
locally.Werecommenddownloadingthecodeanddatabases
usedinthisbook,astheywillhelpyouunderstandtheconcepts
astheyarepresented.
Chapter2andChapter5aredesignedasintroductionstoPHP
andSQL,respectively.Readthembothforanintroductionto
thekeytools,andbeforeyoureadChapter6andlater
chapters.Chapter3andChapter4providemoredetailonPHP
andarestructuredbytopic.Youcanreadthemastutorialsor
usethemasreferencesforfunctionsorconcepts.
Chapter6throughChapter13aretutorial-stylechaptersthat
followthroughtheprinciplesandpracticeofwebdatabase
applications,andincludeannotatedfunctionreferencesand
shortcasestudyexamplestoillustratetheconcepts.Chapter6
throughChapter11describethebasicprinciplesand
componentsandshouldbereadsequentially.Whenyou'veread
thesechapters,you'rereadytostartbuildingyourown
applications.Ifyou'reusingMySQL4.1,thenafteryou'veread
Chapter6,readAppendixHformoreinformationonPHP'snew
improvedMySQLfunctionlibrary.
Chapter12introduceswritingcustomerrorhandlersthatwill
aidyourdebuggingandaddrobustnesstoyourapplication
whenit'sdeployed.Chapter13focusesondevelopingprintable
reportsusingAdobe'sPDFformat.BytheconclusionofChapter
13,youshouldbeamasteroftheprinciplesofdevelopingweb
databaseapplications.
Chapter14andChapter15containadvancedtopics.Theserely
onconceptsfromtheearlierchaptersandgiveyoucomplete
skillsforbuildingsophisticatedapplicationsusingadvanced
programminganddatabasetechniques.Youcanreservethese
optionalchaptersforlater,whenyougetinterestedinadvanced
webdevelopment.Youdon'tneedtoreadthesechaptersto
understandoursampleapplicationinChapter16toChapter20.
Chapter16toChapter20presentandbrieflydiscusscomplete
scriptsfortheonlinewinestorecasestudy.Thescriptsshow
howthetechniquesfromChapter2toChapter12areappliedin
practiceand,assuch,aremostusefulaftermasteringthe
contentoftheearlierchapters.Thematerialintheselater
chaptersismostusefulwhentheexampleapplicationhasbeen
downloadedandinstalledonalocalserver,allowingthescripts
tobemodifiedandtestedasthechaptersareread.
AppendixDandAppendixEarealsoinatutorialstyle.We
recommendAppendixDifyouareinterestedinorare
unfamiliarwiththewebenvironmentanditsunderlying
protocols.AppendixEisabriefintroductiontoentityrelationshipmodelingfordatabasesandshowsthestepswe
tookindesigningthewinestoredatabase.Werecommend
readingAppendixEaftercompletingChapter5.
ConventionsUsedinThisBook
Thefollowingconventionsareusedinthisbook:
Italic
Usedforprogramnames,exampleURLs,anddatabase
entities,andfornewtermswhentheyaredefined.
Constantwidth
Usedforcodeexamples,functions,statements,and
attributes,andtoshowtheoutputofcommands.
Constantwidthitalic
Usedtoindicatevariableswithincommandsandfunctions.
Constantwidthbold
Usedtoindicateemphasisinprogramcode.
Thisicondesignatesanote,whichisanimportantasidetothenearby
text.