Tải bản đầy đủ (.pdf) (1,329 trang)

Sams teach yourself PHP MySQL and apache all in one dec 2003 ISBN 0672326205

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 (9.02 MB, 1,329 trang )






TableofContents
Index

SamsTeachYourselfPHP,MySQL®and
ApacheAllinOne
ByJulieC.Meloni

Publisher :SamsPublishing
PubDate :December18,2003
ISBN :0-672-32620-5
Pages :624


Injustashorttimeyoucanlearnhowtouse
PHP,MySQL,andApachetogethertocreate
dynamic,interactiveWebsitesand
applicationsusingthethreeleadingopensourceWebdevelopmenttechnologies.
Usingastraightforward,step-by-step
approach,eachlessoninthisbookbuildson
thepreviousones,enablingyoutolearnthe
essentialsofPHPscripting,MySQLdatabases,
andtheApacheWebserverfromtheground


up.








TableofContents
Index

SamsTeachYourselfPHP,MySQL®and
ApacheAllinOne
ByJulieC.Meloni

Publisher :SamsPublishing
PubDate :December18,2003
ISBN :0-672-32620-5
Pages :624



Copyright

AbouttheAuthors
Leadauthor

Contributingauthors










Acknowledgments
WeWanttoHearfromYou!
ReaderServices
Introduction
WhoShouldReadThisBook?
HowThisBookIsOrganized
ConventionsUsedinThisBook


PartI.LayingtheGroundwork
Chapter1.InstallingandConfiguringMySQL

CurrentandFutureVersionsofMySQL




HowtoGetMySQL




InstallingMySQLonWindows

InstallingMySQLonLinux/Unix

TroubleshootingYourInstallation




BasicSecurityGuidelines




IntroducingtheMySQLPrivilegeSystem




Summary



Workshop




WorkingwithUserPrivileges
Q&A

Chapter2.InstallingandConfiguringApache
CurrentandFutureVersionsofApache





ChoosinganInstallationMethod




InstallingApacheonWindows




ApacheLogFiles




StartingApachefortheFirstTime




Summary



Workshop

InstallingApacheonLinux/Unix

ApacheConfigurationFileStructure
Apache-RelatedCommands
Troubleshooting
Q&A




Chapter3.InstallingandConfiguringPHP




BuildingPHPonLinux/UnixwithApache




php.iniBasics




GettingInstallationHelp




Summary




Workshop

CurrentandFutureVersionsofPHP
InstallingPHPFilesonWindows
TestingYourInstallation
TheBasicsofPHPScripts
Q&A


PartII.PHPLanguageStructure
Chapter4.TheBuildingBlocksofPHP

Variables




DataTypes




Constants



Q&A


OperatorsandExpressions
Summary






Workshop
Chapter5.FlowControlFunctionsinPHP
SwitchingFlow




Loops




Summary



Workshop




CodeBlocksandBrowserOutput

Q&A

Chapter6.WorkingwithFunctions
WhatIsaFunction?




CallingFunctions




ReturningValuesfromUser-DefinedFunctions




SavingStateBetweenFunctionCallswiththestaticStatement




TestingfortheExistenceofaFunction




Q&A





DefiningaFunction
VariableScope
MoreAboutArguments
Summary
Workshop
Chapter7.WorkingwithArraysandObjects
WhatIsanArray?




CreatingArrays




CreatinganObject




Summary



Workshop


SomeArray-RelatedFunctions
ObjectInheritance
Q&A


PartIII.GettingInvolvedwiththeCode
Chapter8.WorkingwithStrings,Dates,andTimes

FormattingStringswithPHP




InvestigatingStringsinPHP




UsingDateandTimeFunctionsinPHP



Workshop

ManipulatingStringswithPHP
Summary





Chapter9.WorkingwithForms



CreatingaSimpleInputForm




AccessingFormInputwithUser-DefinedArrays




UsingHiddenFieldstoSaveState




SendingMailonFormSubmission




Summary




CombiningHTMLandPHPCodeonaSinglePage

RedirectingtheUser
WorkingwithFileUploads
Workshop
Chapter10.WorkingwithUserSessions
SessionFunctionOverview




StartingaSession




PassingSessionIDsintheQueryString




Summary



Workshop




WorkingwithSessionVariables
DestroyingSessionsandUnsettingVariables

Q&A

Chapter11.WorkingwithFilesandDirectories
IncludingFileswithinclude()




TestingFiles




OpeningaFileforWriting,Reading,orAppending




WritingorAppendingtoaFile




Summary



Workshop





CreatingandDeletingFiles
ReadingfromFiles
WorkingwithDirectories
Q&A

Chapter12.WorkingwiththeServerEnvironment
OpeningPipestoandfromProcessesUsingpopen()




RunningCommandswithexec()




Summary



Workshop

RunningCommandswithsystem()orpassthru()
Q&A

Chapter13.WorkingwithImages






UnderstandingtheImage-CreationProcess



NecessaryModificationstoPHP




DrawingaNewImage




ModifyingExistingImages




Q&A

GettingFancywithPieCharts
Summary
Workshop


PartIV.PHPandMySQLIntegration

Chapter14.LearningtheDatabaseDesignProcess

TheImportanceofGoodDatabaseDesign




TypesofTableRelationships




FollowingtheDesignProcess




Q&A




UnderstandingNormalization
Summary
Workshop
Chapter15.LearningBasicSQLCommands
LearningtheMySQLDataTypes





LearningtheTableCreationSyntax




UsingtheSELECTCommand




SelectingfromMultipleTables




UsingtheREPLACECommand




FrequentlyUsedStringFunctionsinMySQL




Summary




Workshop






UsingtheINSERTCommand
UsingWHEREinYourQueries
UsingtheUPDATECommandtoModifyRecords
UsingtheDELETECommand
UsingDateandTimeFunctionsinMySQL
Q&A

Chapter16.InteractingwithMySQLUsingPHP
ConnectingtoMySQLwithPHP
WorkingwithMySQLData
Summary






Workshop

PartV.BasicProjects




Chapter17.ManagingaSimpleMailingList



DevelopingtheSubscriptionMechanism




DevelopingtheMailingMechanism




Q&A




Summary
Workshop
Chapter18.CreatinganOnlineAddressBook
PlanningandCreatingtheDatabaseTables




CreatingaMenu





ViewingRecords




AddingSubentriestoaRecord



Workshop




CreatingtheRecordAdditionMechanism
CreatingtheRecordDeletionMechanism
Summary

Chapter19.CreatingaSimpleDiscussionForum
DesigningtheDatabaseTables




CreatingtheInputFormsandScripts





DisplayingthePostsinaTopic



Summary




DisplayingtheTopicList
AddingPoststoaTopic

Chapter20.CreatinganOnlineStorefront
PlanningandCreatingtheDatabaseTables




DisplayingCategoriesofItems




Summary




DisplayingItems

Workshop
Chapter21.CreatingaShoppingCartMechanism
PlanningandCreatingtheDatabaseTables




IntegratingtheCartwithYourStorefront



Summary

PaymentMethodsandtheCheckoutSequence




Workshop



Chapter22.CreatingaSimpleCalendar



BuildingaSimpleDisplayCalendar




CreatingaCalendarLibrary




Summary



Workshop




Q&A

Chapter23.RestrictingAccesstoYourApplications
AuthenticationOverview




ApacheAuthenticationModuleFunctionality




CombiningApacheAccessMethods





IntroducingCookies




RestrictingAccessBasedonCookieValues




Q&A




UsingApacheforAccessControl
LimitingAccessBasedonHTTPMethods
SettingaCookiewithPHP
Summary
Workshop
Chapter24.LoggingandMonitoringWebServerActivity
StandardApacheAccessLogging




StandardApacheErrorLogging





LoggingCustomInformationtoaDatabase




Q&A




ManagingApacheLogs
Summary
Workshop
Chapter25.ApplicationLocalization
AboutInternationalizationandLocalization




AboutCharacterSets




CreatingaLocalizedPageStructure





Q&A

EnvironmentModifications
Summary
Workshop






PartVI.AdministrationandFineTuning

Chapter26.ApachePerformanceTuningandVirtualHosting



ScalabilityIssues




LoadTestingwithApacheBench




PreventingAbuse





Summary



ProactivePerformanceTuning
ImplementingVirtualHosting
Q&A
Chapter27.SettingUpaSecureWebServer




TheNeedforSecurity




ObtainingandInstallingSSLTools




SSLConfiguration




Q&A




TheSSLProtocol
ManagingCertificates
Summary

Chapter28.OptimizingandTuningMySQL
BuildinganOptimizedPlatform




MySQLStartupOptions




OptimizingYourQueries




UsingtheSHOWCommand





Q&A




OptimizingYourTableStructure
UsingtheFLUSHCommand
Summary
Workshop
Chapter29.SoftwareUpgrades
StayingintheLoop




UpgradingMySQL




UpgradingPHP



Workshop



UpgradingApache
Summary


PartVII.LookingTowardtheFuture
Chapter30.FeaturesandBackwardCompatibilityofPHP5.0





What'sWrongWithPHP4?



TheNewObjectModel




AdditionalNewFeatures



Summary



Q&A







So,WhenShouldIUpgradetoPHP5?

Chapter31.FeaturesandBackwardCompatibilityofMySQL4.1
UsingSubqueries




InternationalizationEnhancements



LookingFurtherAheadtoMySQL5.0



Summary




Q&A

AdditionalNewFunctionality

Workshop



PartVIII.Appendix
AppendixA.InstallingMySQL,Apache,andPHPfromtheCD-ROM

Linux/UnixInstallation





WindowsInstallation
Troubleshooting
Index


Copyright
Copyright©2004bySamsPublishing
Allrightsreserved.Nopartofthisbookshallbereproduced,
storedinaretrievalsystem,ortransmittedbyanymeans,
electronic,mechanical,photocopying,recording,orotherwise,
withoutwrittenpermissionfromthepublisher.Nopatent
liabilityisassumedwithrespecttotheuseoftheinformation
containedherein.Althougheveryprecautionhasbeentakenin
thepreparationofthisbook,thepublisherandauthorassume
noresponsibilityforerrorsoromissions.Norisanyliability
assumedfordamagesresultingfromtheuseoftheinformation
containedherein.
LibraryofCongressCatalogCardNumber:2003109401
PrintedintheUnitedStatesofAmerica
FirstPrinting:December2003
060504034321


Trademarks
Alltermsmentionedinthisbookthatareknowntobe
trademarksorservicemarkshavebeenappropriately
capitalized.SamsPublishingcannotattesttotheaccuracyof
thisinformation.Useofaterminthisbookshouldnotbe
regardedasaffectingthevalidityofanytrademarkorservice
mark.

WarningandDisclaimer


Everyefforthasbeenmadetomakethisbookascompleteand
asaccurateaspossible,butnowarrantyorfitnessisimplied.
Theinformationprovidedisonan"asis"basis.Theauthorand
thepublishershallhaveneitherliabilitynorresponsibilitytoany
personorentitywithrespecttoanylossordamagesarising
fromtheinformationcontainedinthisbookorfromtheuseof
theCDorprogramsaccompanyingit.

BulkSales
SamsPublishingoffersexcellentdiscountsonthisbookwhen
orderedinquantityforbulkpurchasesorspecialsales.For
moreinformation,pleasecontact
U.S.CorporateandGovernmentSales
1-800-382-3419

ForsalesoutsideoftheU.S.,pleasecontact
InternationalSales
+1-317-428-3341



Credits
AcquisitionsEditor
ShelleyJohnston
DevelopmentEditor
ChrisNewman
ManagingEditor


CharlotteClapp
ProjectEditor
DanKnott
CopyEditor
KristaHansing
Indexer
SharonShock
Proofreader
MikeHenry
TechnicalEditor
ChrisNewman
PublishingCoordinator
VanessaEvans
MultimediaDeveloper
DanScherf
Designer
GaryAdair
PageLayout
JulieParks



AbouttheAuthors
Leadauthor
Contributingauthors


Leadauthor
JulieC.Meloniisthetechnicaldirectorfori2iInteractive
(),amultimediacompanylocatedinLos
Altos,California.She'sbeendevelopingWeb-basedapplications
sincetheWebfirstsawthelightofdayandremembersthe
excitementsurroundingthefirstGUIWebbrowser.Shehas
authoredseveralbooksandarticlesonWeb-based
programminglanguagesanddatabasetopics,andyoucanfind
translationsofherworkinseverallanguages,includingChinese,
Italian,Portuguese,Polish,andevenSerbian.


Contributingauthors
MattZandstraisawriterandconsultantspecializinginserver
programming.Withhisbusinesspartner,MaxGuglielmino,he
runsCorrosive(),atechnicalagency
thatplans,designsandbuildsInternetapplications.Mattis
interestedinallaspectsofobject-orientedprogramming,andis
currentlyexploringenterprisedesignpatternsforPHP5.When
heisnotreading,writing,orthinkingaboutcodinginPHPand
Java,Mattshootsalieninvadersintheparkwithhisfour-yearolddaughter,Holly.HelivesbytheseainBrighton,Great
Britain,withhispartnerLouiseMcDougall,andtheirchildren
HollyandJake.
DanielLópezRidruejoisthefounderofBitRock,atechnology

companyprovidingmultiplatforminstallationandmanagement
toolsforavarietyofcommercialandopensourcesoftware
products.Previously,hewaspartoftheoriginalengineering
teamatCovalentTechnologies,Inc.,whichprovidesApache
software,support,andservicesfortheenterprise.Heisthe
authorofseveralpopularApacheandLinuxguides,the
mod_monomoduleforintegratingApacheand.NET,andof
Comanche,aGUIconfigurationtoolforApache.Danielisa
regularspeakeratopensourceconferencessuchasLinux
World,ApacheCon,andtheO'ReillyOpenSourceConvention.
HeholdsaMasterofSciencedegreeinTelecommunications
fromtheEscuelaSuperiordeIngenierosdeSevillaand
DanmarksTekniskeUniversitet.Danielisamemberofthe
ApacheSoftwareFoundation.


Acknowledgments
TheApacheFoundation,thePHPGroup,andMySQLABdeserve
muchmorerecognitionthantheyevergetforcreatingthese
superproductsthatdriveagreatportionoftheWeb.
DanielLòpez(authorofSamsTeachYourselfApache2in24
Hours)andMattZandstra(authorofSamsTeachYourselfPHP
in24Hours)wrotesuperbooks,whichformaportionofthis
book.Obviously,thisbookwouldnotexistwithouttheirwork!
Greatthanksespeciallytoalltheeditorsandlayoutfolksat
Samswhowereinvolvedwiththisbook,foralltheirhardwork
inseeingthisthrough!Thanksasalwaystoeveryoneati2i
Interactivefortheirnever-endingsupportandencouragement.



WeWanttoHearfromYou!
Asthereaderofthisbook,youareourmostimportantcritic
andcommentator.Wevalueyouropinionandwanttoknow
whatwe'redoingright,whatwecoulddobetter,whatareas
you'dliketoseeuspublishin,andanyotherwordsofwisdom
you'rewillingtopassourway.
Youcanemailorwritemedirectlytoletmeknowwhatyoudid
ordidn'tlikeaboutthisbookaswellaswhatwecandotomake
ourbooksstronger.
PleasenotethatIcannothelpyouwithtechnicalproblems
relatedtothetopicofthisbook,andthatduetothehigh
volumeofmailIreceive,Imightnotbeabletoreplytoevery
message.
Whenyouwrite,pleasebesuretoincludethisbook'stitleand
authoraswellasyournameandphoneoremailaddress.Iwill
carefullyreviewyourcommentsandsharethemwiththeauthor
andeditorswhoworkedonthebook.

Email:



Mail:

MarkTaber
AssociatePublisher
SamsPublishing
800East96thStreet
Indianapolis,IN46240USA



ReaderServices
FormoreinformationaboutthisbookorothersfromSams
Publishing,visitourWebsiteatwww.samspublishing.com.Type
theISBN(excludinghyphens)orthetitleofthebookinthe
Searchboxtofindthebookyou'relookingfor.


Introduction
WelcometoSamsTeachYourselfPHP,MySQL,andApacheAll
inOne!ThisbookcombinesthelessonsfoundinSamsTeach
YourselfApache2in24Hours,SamsTeachYourselfPHPin24
Hours,andSamsTeachYourselfMySQLin24Hours,alongwith
severaladditionalchapters,toprovideyouwithasolidand
painlessintroductiontotheworldofdevelopingWeb-based
applicationsusingthesethreetechnologies.
Overthecourseofthisbook,you'lllearntheconcepts
necessaryforconfiguringandmanagingApache,thebasicsof
programminginPHP,andthemethodsforusingand
administeringtheMySQLrelationaldatabasesystem.The
overallgoalofthebookistoprovideyouwiththefoundation
youneedtounderstandhowseamlesslythesetechnologies
integratewithoneanother,andtogiveyoupracticalknowledge
ofhowtointegratethem.


WhoShouldReadThisBook?
Thisbookisgearedtowardindividualswhopossessageneral
understandingoftheconceptsofworkinginaWeb-based
developmentenvironment,beitLinux/UnixorWindows.

Installationandconfigurationlessonsassumethatyouhave
familiaritywithyouroperatingsystemandthebasicmethodsof
building(onLinux/Unixsystems)orinstalling(onWindows
systems)software.
ThelessonsthatdelveintoprogrammingwithPHPassumeno
previousknowledgeofthelanguage,butifyouhaveexperience
withotherprogramminglanguages,suchasCorPerl,youwill
findthegoingmucheasier.Similarly,ifyouhaveworkedwith
otherdatabases,suchasOracleorMicrosoftSQLServer,you
willhaveagoodfoundationforworkingthroughtheMySQLrelatedlessons.
TheonlyrealrequirementisthatyouunderstandstaticWeb
contentcreationwithHTML.Ifyouarejuststartingoutinthe
worldofWebdevelopment,youwillstillbeabletousethis
book,althoughyoushouldconsiderworkingthroughanHTML
tutorial.Ifyouarecomfortablecreatingbasicdocumentsand
canbuildabasicHTMLtable,youwillbefine.


HowThisBookIsOrganized
Thisbookisdividedintosevenparts,correspondingto
particulartopicgroups.Thelessonswithineachpartshouldbe
readonerightafteranother,witheachlessonbuildingonthe
informationfoundinthosebeforeit:
PartI,"LayingtheGroundwork,"walksyouthroughthe
installationandconfigurationofMySQL,Apache,andPHP.
You'llneedtocompletethelessonsinPartIbeforemoving
on,unlessyoualreadyhaveaccesstoaworkinginstallation
ofthesetechnologies.Evenifyoudon'tneedtoinstalland
configureMySQL,Apache,andPHPinyourenvironment,
youshouldstillskimtheselessonssothatyouunderstand

thebasics.
PartII,"PHPLanguageStructure,"isdevotedtoteaching
youthebasicsofthePHPlanguage,includingstructural
elementssuchasarraysandobjects.Theexampleswillget
youinthehabitofwritingcode,uploadingittoyourserver,
andtestingtheresults.
PartIII,"GettingInvolvedwiththeCode,"consistsof
lessonsthatcoverintermediate-levelapplicationdevelopmenttopics,includingworkingwithformsandfiles,
restrictingaccess,andcompletingothersmallprojects
designedtointroduceaspecificconcept.
PartIV,"PHPandMySQLIntegration,"containslessons
devotedtoworkingwithdatabasesingeneral,suchas
databasenormalization,aswellasusingPHPtoconnectto
andworkwithMySQL.IncludedisabasicSQLprimer,which
alsoincludesMySQL-specificfunctionsandother
information.


PartV,"BasicProjects,"consistsoflessonsdevotedto
performingaparticulartaskusingPHPandMySQL,
integratingalltheknowledgegainedsofar.Projectsinclude
anaddressbook,adiscussionforum,andabasiconline
storefront,amongothers.
PartVI,"AdministrationandFineTuning,"isdevotedto
administeringandtuningApacheandMySQL.Italso
includesinformationonvirtualhostingandsettingupa
secureWebserver.
PartVII,"LookingTowardtheFuture,"containsinformation
regardingtheupcomingmajorreleasesofPHP5.0and
MySQL4.1.

Ifyoufindthatyouarealreadyfamiliarwithatopic,youcan
skipaheadtothenextlesson.However,insomeinstances,
lessonsrefertospecificconceptslearnedinpreviouschapters,
sobeawarethatyoumighthavetoskimaskippedlessonso
thatyourdevelopmentenvironmentremainsconsistentwiththe
book.
Attheendofeachchapter,afewquizquestionstesthowwell
you'velearnedthematerial.Additionalactivitiesprovide
anotherwaytoapplytheinformationlearnedinthelessonand
guideyoutowardusingthisnewfoundknowledgeinthenext
chapter.


ConventionsUsedinThisBook
Thisbookusesdifferenttypefacestodifferentiatebetweencode
andplainEnglish,andalsotohelpyouidentifyimportant
concepts.Throughoutthelessons,code,commands,andtext
youtypeorseeonscreenappearinacomputertypeface.New
termsappearinitalicsatthepointinthetextwheretheyare
defined.Additionally,iconsaccompanyspecialblocksof
information:
A"BytheWay"presentsaninterestingpieceofinformation
relatedtothecurrenttopic.

A"DidYouKnow"offersadviceorteachesaneasiermethodfor
performingatask.

A"WatchOut"warnsyouaboutpotentialpitfallsandexplainshow
toavoidthem.



×