




已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
0外文原文GettingPHPtoTalktoMySQlNowthatyourecomfortableusingtheMySQLclienttoolstomanipulatedatainthedatabase,youcanbeginusingPHPtodisplayandmodifydatafromthedatabase.PHPhasstandardfunctionsforworkingwiththedatabase.First,weregoingtodiscussPHPsbuilt-indatabasefunctions.WellalsoshowyouhowtousetheThePHPExtensionandApplicationRepository(PEAR)databasefunctionsthatprovidetheabilitytousethesamefunctionstoaccessanysupporteddatabase.Thistypeofflexibilitycomesfromaprocesscalledabstraction.Inprogramminginterfaces,abstractionsimplifiesacomplexinteraction.Itworksbyremovinganynonessentialpartsoftheinteraction,allowingyoutoconcentrateontheimportantparts.PEARsDBclassesareonesuchdatabaseinterfaceabstraction.Theinformationyouneedtologintoadatabaseisreducedtothebareminimum.ThisstandardformatallowsyoutointeractwithMySQL,aswellasotherdatabasesusingthesamefunctions.Similarly,otherMySQL-specificfunctionsarereplacedwithgenericonesthatknowhowtotalktomanydatabases.Forexample,theMySQL-specificconnectfunctionis:mysql_connect($db_host,$db_username,$db_password);versusPEARsDBconnectfunction:$connection=DB:connect(mysql:/$db_username:$db_password$db_host/$db_database);Thesamebasicinformationispresentinbothcommands,butthePEARfunctionalsospecifiesthetypeofdatabasestowhichtoconnect.YoucanconnecttoMySQLorothersupporteddatabases.Welldiscussbothconnectionmethodsindetail.Inthischapter,youlllearnhowtoconnecttoaMySQLserverfromPHP,howtousePHPtoaccessandretrievestoreddata,andhowtocorrectlydisplayResources.WhenconnectingtoaMySQLdatabase,youwillusetwonewresources.Thefirstisthelinkidentifierthatholdsalloftheinformationnecessarytoconnecttothedatabaseforanactiveconnection.Theotherresourceistheresultsresource.1Itcontainsallinformationrequiredtoretrieveresultsfromanactivedatabasequerysresultset.Youllbecreatingandassigningbothresourcesinthischapter.QueryingtheDatabasewithPHPFunctionsInthissection,weintroducehowtoconnecttoaMySQLdatabasewithPHP.Itsquitesimple,andwellbeginshortlywithexamples,butweshouldtalkbrieflyaboutwhatactuallyhappens.WhenyoutryconnectingtoaMySQLdatabase,theMySQLserverauthenticatesyoubasedonyourusernameandpassword.PHPhandlesconnectingtothedatabaseforyou,anditallowsyoutostartperformingqueriesandgatheringdataimmediately.AsinChapter8,wellneedthesamepiecesofinformationtoconnecttothedatabase:TheIPaddressofthedatabaseserverThenameofthedatabaseTheusernameThepasswordBeforemovingon,makesureyoucanlogintoyourdatabaseusingtheMySQLcommand-lineclient.Figure9-1showshowthestepsofthedatabaseinteractionrelatetothetwotypesofresources.BuildingtheSELECTstatementhappensbeforethethirdfunctioncall,butitisnotshown.ItsdonewithplainPHPcode,notaMySQL-specificPHPfunction.Figure9-1.TheinteractionbetweenfunctionsandresourceswhenusingthedatabaseIncludingDatabaseLoginDetailsYouregoingtocreateafiletoholdtheinformationforloggingintoMySQL.Storingthisinformationinafileyouincludeisrecommended.Ifyouchangethedatabasepassword,thereisonlyoneplacethatyouneedtochangeit,regardlessofhowmanyPHPfilesyouhavethataccessthedatabase.Youdonthavetoworryaboutanyonedirectlyviewingthefileandgettingyourdatabaselogindetails.Thefile,ifrequestedbyitself,isprocessedasaPHPfileandreturnsablankpage.TroubleshootingconnectionerrorsOneerroryoumaygetis:informationtotheuser.TheProcessThebasicstepsofperformingaquery,whetherusingthemysqlcommand-linetoolorPHP,arethesame:Connecttothedatabase.Selectthedatabasetouse.BuildaSELECTstatement.Performthequery.Displaytheresults.WellwalkthrougheachofthesestepsforbothplainPHPandPEARfunctions.Fatalerror:2Calltoundefinedfunctionmysql_connect()inC:ProgramFilesApacheSoftwareFoundationApache2.2htdocsdb_test.phponline4ThiserroroccursbecausePHP5.xforWindowswasdownloaded,andMySQLsupportwasnotincludedbydefault.Tofixthiserror,copythephp_mysql.dllfilefromtheext/directoryofthePHPZIPfiletoC:php,andthenC:WINDOWSphp.ini.Makesuretherearetwolinesthatarenotcommentedoutbyasemicolon(;)atthebeginningofthelinelikethese:extension_dir=c:/PHP/ext/extension=php_mysql.dllThiswillchangetheextensiontoincludethedirectorytoC:/phpandincludetheMySQLextension,respectively.YoucanusetheSearchfunctionofyourtexteditortocheckwhetherthelinesarealreadythereandjustneedtobeuncommented,orwhethertheyneedtobeaddedcompletely.YoullneedtorestartApache,andthenMySQLsupportwillbeenabled.SelectingtheDatabaseNowthatyoureconnected,thenextstepistoselectwhichdatabasetousewiththemysql_select_dbcommand.Ittakestwoparameters:thedatabasenameand,optionally,thedatabaseconnection.Ifyoudontspecifythedatabaseconnection,thedefaultistheconnectionfromthelastmysql_connect:/Selectthedatabase$db_select=mysql_select_db($db_database);if(!$db_select)die(Couldnotselectthedatabase:.mysql_error();Again,itsgoodpracticetocheckforanerroranddisplayiteverytimeyouaccessthedatabase.Nowthatyouvegotagooddatabaseconnection,yourereadytoexecuteyourSQLquery.BuildingtheSQLSELECTQueryBuildingaSQLqueryisaseasyassettingavariabletothestringthatisyourSQLquery.Ofcourse,youllneedtouseavalidSQLquery,orMySQLreturnswithanerrorwhenyouexecutethequery.Thevariablename$queryisusedsincethenamereflectsitspurpose,butyoucanchooseanythingyoudlikeforavariablename.TheSQLqueryinthisexampleisSELECT*FROMbooks.Youcanbuildupyourqueryinpartsusingthestringconcatenate(.)3operator:ExecutingtheQueryTohavethedatabaseexecutethequery,usethemysql_queryfunction.Ittakestwoparametersthequeryand,optionally,thedatabaselinkandreturnstheresult.Savealinktotheresultsinavariablecalled,youguessedit,$result!Thisisalsoagoodplacetocheckthereturncodefrommysql_querytomakesurethattherewerenoerrorsinthequerystringorthedatabaseconnectionbyverifyingthat$resultisnotFALSE:Whenthedatabaseexecutesthequery,alloftheresultsformaresultset.Theseresultscorrespondtotherowsthatyousawupondoingaqueryusingthemysqlcommand-lineclient.Todisplaythem,youprocesseachrow,oneatatime.FetchingandDisplayingUsemysql_fetch_rowtogettherowsfromtheresultset.Itssyntaxis:arraymysql_fetch_row(resource$result);Ittakestheresultyoustoredin$resultfromthequeryasaparameter.Itreturnsonerowatatimefromthequeryuntiltherearenomorerows,andthenitreturnsFALSE.Therefore,youdoaloopontheresultofmysql_fetch_rowanddefinesomecodetodisplayeachrow:Thecolumnsoftheresultrowarestoredinthearrayandcanbeaccessedoneatatime.Thevariable$result_row2accessesthesecondattribute(asdefinedinthequeryscolumnorderorthecolumnorderofthetableifSELECT*isused)intheresultrow.FetchtypesThisisnottheonlywaytofetchtheresults.Usingmysql_fetch_array,PHPcanplacetheresultsintoanarrayinonestep.Ittakesaresultasitsfirstparameter,andthewaytobindtheresultsasanoptionalsecondparameter.IfMYSQL_ASSOCisspecified,theresultsareindexedinanarraybasedontheircolumnnamesinthequery.IfMYSQL_NUMisspecified,thenthenumberstartingatzeroaccessestheresults.Thedefaultvalue,MYSQL_BOTH,returnsaresultarraywithbothtypes.Themysql_fetch_associsanalternativetosupplyingtheMYSQL_ASSOCargument.ClosingtheConnectionAsaruleofthumb,youalwayswanttocloseaconnectiontoadatabasewhenyouredoneusingit.Closingadatabasewithmysql_closewilltellPHPandMySQLthatyounolongerwillbeusingtheconnection,andwillfreeanyresourcesandmemoryallocatedtoit:mysql_close($connection)4InstallingPEARusesaPackageManagerthatoverseeswhichPEARfeaturesyouinstall.WhetheryouneedtoinstallthePackageManagerdependsonwhichversionofPHPyouinstalled.IfyourerunningPHP4.3.0ornewer,itsalreadyinstalled.IfyourerunningPHP5.0,PEARhasbeensplitoutintoaseparatepackage.TheDBpackagethatyoureinterestedinisoptionalbutinstalledbydefaultwiththePackageManager.SoifyouhavethePackageManager,youreallset.UnixYoucaninstallthePackageManageronaUnixsystembyexecutingthefollowingfromtheshell(command-line)prompt:lynx-source/|phpTsite(whichisactuallythesourcePHPcode)toinstallPEARandpassesitalongtothephpcommandforexecution.WindowsThePHP5installationincludesthePEARinstallationscriptasC:phpgo-pear.bat.IncaseyoudidntinstallallthefilesinChapter2,goaheadandextractallthePHPfilestoC:/phpfromthecommandprompt,andexecutethe.batfile.CreatingaconnectinstanceTheDB.phpfiledefinesaclassoftypeDB.RefertoChapter5formoreinformationonworkingwithclassesandobjects.Wellprincipallybecallingthemethodsintheclass.TheDBclasshasaconnectmethod,whichwelluseinsteadofouroldconnectfunction,mysql_connect.Thedoublecolons(:)indicatethatwerecallingthatfunctionfromtheclassinline4:$connection=DB:connect(mysql:/$db_username:$db_password$db_host/$db_database);Whenyoucalltheconnectfunction,itcreatesanewdatabaseconnectionthatisstoredinthevariable$connection.Theconnectfunctionattemptstoconnecttothedatabasebasedontheconnectstringyoupassedtoit.ConnectstringTheconnectstringusesthisnewformattorepresentthelogininformationthatyoualreadysuppliedinseparatefields:dbtype:/username:passwordhost/databaseThisformatmaylookfamiliartoyou,asitsverysimilartotheconnectstringforaWindowsfileshare.ThefirstpartofthestringiswhatreallysetsthePEARfunctionsapartfromtheplainPHP.Thephptypefieldspecifiesthetypeofdatabasetoconnect.Supporteddatabasesincludeibase,msql,mssql,mysql,oci8,odbc,pgsql,andsybase.Allthatsrequiredforyour5PHPpagetoworkwithadifferenttypeofdatabaseischangingthephptype!Theusername,password,host,anddatabaseshouldbefamiliarfromthebasicPHPconnect.Onlythetypeofconnectionisrequired.However,youllusuallywanttospecifyallfields.Afterthevaluesfromdb_login.phpareincluded,theconnectstringlookslikethefollowing:mysql:/test:testlocalhost/testIftheconnectmethodonline6wassuccessful,aDBobjectiscreated.Itcontainsthemethodstoaccessthedatabaseaswellasalloftheinformationaboutthestateofthatdatabaseconnection.QueryingOneofthemethodsitcontainsiscalledquery.ThequerymethodworksjustlikePHPsqueryfunctioninthatittakesaSQLstatement.Thedifferenceisthatthearrowsyntax(-)isusedtocallitfromtheobject.Italsoreturnstheresultsasanotherobjectinsteadofaresultset:$query=SELECT*FROMbooks$result=$connection-query($query);BasedontheSQLquery,thiscodecallsthequeryfunctionfromtheconnectionobjectandreturnsaresultobjectnamed$result.FetchingLine22usestheresultobjecttocallthefetchRowmethod.Itreturnstherowsoneatatime,similartomysql_fetch_row:while($result_row=$result-fetchRow()echoTitle:.$result_row1.;echoAuthor:.$result_row4.;echoPages:.$result_row2.;UseanotherwhilelooptogothrougheachrowfromfetchRowuntilitreturnsFALSE.Thecodeintheloophasntchangedfromthenon-PEARexample.ClosingYourefinishedwiththedatabaseconnection,socloseitusingtheobjectmethoddisconnect:$connection-disconnect();PEARerrorreportingThefunctionDB:isErrorwillchecktoseewhethertheresultthatsbeenreturnedtoyouisanerror.Ifitisanerror,youcanuseDB:errorMessagetoreturnatextdescriptionoftheerrorthatwasgenerated.YouneedtopassDB:errorMessage,thereturnvaluefromyourfunction,asanargument.HereyourewritethePEARcodetouseerrorchecking:query($sql)echoDB:errorMessage($demoResult);elsewhile($demoRow=$demoResult-fetchRow()echo$demoRow2.;?TheresalsoanewversionofthePEARdatabaseinterfacecalledPEAR:MDB2.Thesameresultsdisplay,buttherearemorefunctionsavailableinthisversionofthePEARdatabaseabstractionlayer.7中文翻译通过PHP访问MySQL现在你已经可以熟练地使用MySQL客户端软件来操作数据库里的数据,我们也可以开始学习如何使用PHP来显示和修改数据库里的数据了。PHP有标准的函数用来操作数据库。我们首先学习PHP内建的数据库函数,然后会学习PHP扩展和应用程序库(PEAR,PHPExtensionandApplicationRepository)中的数据库函数,我们可以使用这些函数操作所有支持的数据库。这种灵活性源自于抽象。对于编程接口而言,抽象简化了复杂的交互过程。它将交互过程中无关紧要的部分屏蔽起来,让你关注于重要的部分。PEAR的DB类就是这样一种数据库接口的抽象。你登录一个数据库所需要提供的信息被减少到最少。这种标准的格式可以通过同一个函数来访问MySQL以及其他的数据库。同样,一些MySQL特定的函数被更一般的、可以用在很多数据库上的函数所替代。比如,MySQL特定的连接函数是:mysql_connect($db_host,$db_username,$db_password);而PEAR的DB提供的连接函数是:$connection=DB:connect(mysql:/$db_username:$db_password$db_host/$db_database);两个命令都提供了同样的基本信息,但是PEAR的函数中还指定了要连接的数据库的类型。你可以连接到MySQL或者其他支持的数据库。我们会详细讨论这两种连接方式。本章中,我们会学习如何从PHP连接到MySQL的服务器,如何使用PHP访问数据库中存储的数据,以及如何正确的向用户显示信息。步骤无论是通过MySQL命令行工具,还是通过PHP,执行一个查询的基本步骤都是一样的:连接到数据库选择要使用的数据库创建SELECT语句执行查询显示结果我们将逐一介绍如何用PHP和PEAR的函数完成上面的每一步。资源当连接到MySQL数据库的时候,你会使用到两个新的资源。第一个是连接的标识符,它记录了一个活动连接用来连接到数据库所必需的所有信息。另外一个资源是结果资源,它包含了用来从一个有效的数据库查询结果中取出结果所需要的所有信息。本章中我们会创建并使用这两种资源。使用PHP函数查询数据库8本节我们会介绍如何使用PHP连接MySQL数据库。这非常简单,我们会用一些例子说明。但是之前我们应该稍微了解一下幕后发生的事情。当你试图连接一个MySQL数据库的时候,MySQL服务器会根据你的用户名和密码进行身份认证。PHP为你建立数据库的连接,你可以立即开始查询并得到结果。我们需要同样的信息来连接数据库:数据库服务器的IP地址数据库的名字用户名密码在开始之前,首先使用MySQL的命令行客户端确认你登录到数据库。图9-1显示了数据库交互过程的各个步骤和两种类型资源之间的关系。创建SELECT语句发生在第三个函数调用之前,但是在图中没有显示出来。它是通过普通的PHP代码,而不是MySQL特定的PHP函数完成的。图9-1:使用数据库时函数和资源之间的交互包含数据库登录细节我们先创建一个文件,用来保存登录MySQL所用到的信息。我们建议你把这些信息放在单独的文件里然后通过include来使用这个文件。这样一来如果你修改了数据库的密码。无论有多少个PHP文件访问数据库,你只需要修改这一个文件。注意:不用担心有人会直接看到这个文件从而得到你的数据库的登录信息。如何被直接请求,这个文件会被当作PHP文件处理,返回结果是一个空白页。假设这个文件的名字叫做db_login.php,并且它跟其他所用PHP文件放在同一个目录下。这个文件的内容如例9-1所示。例9-1:设置数据库登录的配置文件模板在例9-2中,我们创建的文件使用跟Web服务器放在同一台机器上的数据库,并指定的数据库的名字,用户名和密码。例9-2:db_login.php文件示例图9-2显示了如何在其他PHP文件中使用这个文件。我们会继续使用在第七章中创建的数据库。图9-2:在多文件中重复使用登录信息例9-3是精简后的,用mysqldump命令得到的重建这个数据库的SQL命令。9例9-3:重建测试数据库的SQL语句DROPTABLEIFEXISTSbooks;CREATETABLEbooks(title_idint(11)NOTNULLauto_increment,titlevarchar(150)defaultNULL,pagesint(11)defaultNULL,PRIMARYKEY(title_id)ENGINE=MyISAMDEFAULTCHARSET=latin1;-Dumpingdatafortablebooks-INSERTINTObooksVALUES(1,LinuxinaNutshell,476),(2,ClassicShellScripting,256);-Tablestructurefortablepurchases-DROPTABLEIFEXISTSpurchases;CREATETABLEpurchases(idint(11)NOTNULLauto_increment,uservarchar(10)defaultNULL,titlevarchar(150)defaultNULL,daydatedefaultNULL,PRIMARYKEY(id)ENGINE=MyISAMDEFAULTCHARSET=latin1;-Dumpingdatafortablepurchases-LOCKTABLESpurchasesWRITE;INSERTINTOpurchasesVALUES(1,Mdavis,RegularExpressionPocketReference,2005-02-15),(2,Mdavis,JavaScript&DHTMLCookbook,2005-02-10);如果你在第8章中没有创建这些表,可以将例9-3中的代码保存成文件backup.sql,然后在命令行执行命令,命令格式如下:mysql-uusername-ppassword-Ddatabase_name.mysql_error();函数mysql_connect的参数是数据库服务器主机、用户名和密码。如果连接成功,就会返回新建立的连接,如果不能建立连接就会返回FALSE。检查这个函数的返回值来确保连接的确建立起来了。如果遇到问题,比如不正确的密码,可以使用mysql_error打印一条友好的警告信息以及导致错误的原因。注意:不仅仅是打印一条错误信息,die()还会停止这个程序的执行。对于大部分数据库驱动网页来说,不能访问数据库就意味着网页毫无用处。通过使用die来终止程序的执行,可以避免用户看到大量的错误信息。请注意我们还没有指定数据库的名字。诊断连接错误你可能遇到的一个错误是:Fatalerror:Calltoundefinedfunctionmysql_connect()inC:ProgramFilesApacheSoftwareFoundationApache2.2htdocsdb_test.phponline4这个错误发生的原因是下载安装的PHP5.x默认没有包括对MySQL的支持。解决这个问题需要将php_mysql.dll文件从PHP压缩包例的ext/目录复制到C:/php,并修改C:WINDOWSphp.ini文件,确保下面两行没有被注释掉(注释的方法在行首使用分号)。extension_dir=c:/PHP/ext/extension=php_mysql.dll这样PHP扩展的目录就被设为C:PHP,MySQL的扩展也会被使用。在编辑php.ini文件的时候,你可以使用编辑器的搜索功能来检查这两行是否已经存在,只是需要去掉注释,并且需要重新输入。重新启动Apache,这样MySQL的支持就会被打开了。选择数据库建立连接之后,下一步就是使用mysql_select_db来选择我们要用的数据库。它的参数有两个:数据库名和可选的数据库连接。如果不指定数据库连接,默认使用上一条mysql_connect所建立的连接。/Selectthedatabase$db_select=mysql_select_db($db_database);if(!$db_select)die(Couldnotselectthedatabase:.mysql_error();同样的,每次访问数据库的时候最好能检查可能的错误并且进行显示。注意:虽然可以在同一个脚本里多次调用mysql_select_db,但这不是一个11好习惯。现在我们做好了一切准备工作,可以开始执行SQL查询了。构建SQLSELECT查询构建SQL查询非常容易就是将一个字符串赋值给变量。这个字符串就是我们的SQL查询,当然我们要给出有效的SQL查询,否则执行这个查询的时候MySQL会返回错误。我们使用$query作为变量名,这个名字对应其目的,你也可以选择任何你喜欢的变量名。这个例子中的SQL查询是”SELECT*FROMbooks”。注意:跟使用mysql命令行客户端不同,这里的查询不需要以分号结尾。你可以使用字符串连接操作符(.)来构建查询:/Assignthequery$select=SELECT;$column=*;$from=FROM;$tables=books;$where=NATURALJOINauthors;$query=$select.$column.$from.$tables.$where;这个版本的代码比下面的代码要灵活多了:/Assignthequery$query=SELECT*FROMbooksNATURALJOINauthors;查询字符串也可以在WHERE子句中使用变量来限定返回什么样的行,这些变量可能是用户信息,也可能是来自其他的查询。现在我们已经将查询赋值给了一个变量,下一步就是执行它。执行查询使用mysql_query函数来告诉数据库执行查询。它有两个参数:查询和可选的数据库连接,返回值是查询结果。我们将查询结果保存在一个变量里,也许你已经猜到我们要用变量名就是$result。这里同样有必要检查mysql_query的返回值不是FALSE来确保查询字符串和数据库连接都没有问题。/Executethequery$result=mysql_query($query);if(!$result)die(Couldnotquerythedatabase:.mysql_error();当数据库查询的时候,所有的结果构成一个结果集。这些结果跟使用mysql命令行客户端执行同样查询所得到的行一致。要显示这些结果,你需要依次处理这些行。取结果并显示使用mysql_fetch_row从结果集中取出一行,它的用法如下:arraymysql_fetch_row(resource$result);它的参数是SQL查询返回的结果,我们将结果保存在$result中。每次调用它返回一行数据,直到没有数据为止,这时候它返回FALSE。这样,我们可以使用一个循环,在循环内调用mysql_fetch_row并使用一些代码来显示每一行。/Fetchanddisplaytheresultswhile($result_row=mysql_fetch_row($result)12echoTitle:.$result_row1.;echoAuthor:.$result_row4.;echoPages:.$result_row2.;结果行的所有列都保存在一个数组里,可以方便地进行访问。变量$result_row2访问结果行的第二个属性(数组的顺序是查询是定义的列的顺序,如果使用SELECE*,那么数组顺序就是表的列的顺序)。取结果的方式去结果的方式不止一种。使用mysql_fetch_arrry可以一次性将所有结果放在一个数组里。它的参数是查询结果和一个可选的结果绑定方式。如果绑定方式指定为MYSQL_ASSOC,数组中的结果则使用查询中列的名字进行访问。如果指定了MYSQL_NUM,那么就使用从0开始的数字来访问结果。默认使用的方式是MYSQL_BOTH,这样返回的数组支持两种类型的访问。Mysql_fetch_assoc是使用MYSQL_ASSOC取结果的另外一种方式。用mysql_fetch_array加上MYSQL_ASSOC的方式重写上面的代码,如下所示:/Fetchanddisplaytheresultswhile($result_row=mysql_fetch_array($result,MYSQL_ASSOC)echoTitle:.$result_rowtitle.;echoAuthor:.$result_rowauthor.;echoPages:.$result_rowpages.;关闭连接绝大部分情况下,我们在使用完一个数据库之后要关闭到它的连接。使用mysql_close来关闭一个数据库,它会告诉PHP和MySQL这个数据库连接已经不再使用,所使用的所有资源和内存都可以释放。mysql_close($connection)使用PEARPEAR是一个框架和可重用PHP组建的发布系统,它为PHP开发提供了一套增强的功能,PEAR包括很多种模块,用来处理从会话管理到购物车功能的几乎所有事情。表9-1列出了现有的模块种类。表9-1:PEAR模块种类AuthenticationHTMLProcessingBenchmarkingHTTPScienceCachingImagesSemanticWebConfigurationInternationalizationStreamsConsoleLoggingStructuresDatabaseMailSystemDate/TimeMathTestEncryptionNetworkingToolsandutilitiesEventNumbersValidateFileformatsPaymentWebservicesFilesystemPEARXMLGTKcomponentsPHP13我们的列表还不够完整,可以访问来获得供下载的所有模块。安装PEAR使用包管理器来管理安装PEAR模块。是否需要安装包管理取决于你所使用的PHP版本。如果你使用的版本是PHP4.4.0或者更新的版本,那么就已经安装了包管理器。如果你使用的是PHP5.0,则PEAR是一个单独的包。我们要用到的DB包是可选的,但是它会被包管理器默认安装。所以,如果你有包管理器,那么就全搞定了。UNIX在UNIX系统下,可以通过在shell(命令行)下执行下面的命令来安装包管理器:lynx-source/|php这个命令使用的输出(实际就是PHP源代码)来安装PEAR,的输出被传给php命令执行。Windows安装完PHP5后,会有一个PEAR安装脚本C:phpgo-pear.bat。如果你在第二章没有安装所以文件,那么现在把所有的PHP文件都解压到C:php下,然后执行这个批处理文件。注意:如果你是通过MSI安装程序安装PHP,需要执行下面的命令而不是使用go-pear.bat文件:phpgo-pear.phar如果PEAR目录不存在,那就需要重新执行PHP的MSI安装程序,选择Change选项,然后将“ExtensionsandExtras”设置成“Willbeinstalledonlocaldrive”。完毕后再执行go-pear.phar。图9-5显示执行PEAR安装程序后的初始屏幕。图9-5:go-pear.bat安装脚本安装程序会要求输入几个路径,你可以使用默认值。那样安装的最上级目录就是c:php.注意:php.exe必须位于系统路径中。在命令行输入php.exe来确认。如果没有找到这个命令,那需要将它的路径加到PATH变量中。要修改系统的PATH变量,选择“开始控制面板系统环境变量”,在PATH变量的后面增加一项“C:php”。PEAR安装程序会创建文件C:phpPEAR_ENV.reg,双击该文件在注册表中设置PEAR的路径。这个文件的内容视安装的PEAR版本而定。当弹出对话框要求确认的时候,点击OK
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年福建省泉州市安溪龙门中学招聘1人考前自测高频考点模拟试题及答案详解(历年真题)
- 呼兰河传考试题目及答案
- 河南文综考试题目及答案
- 新解读《GB-T 39351-2020空间数据与信息传输系统 遥测空间数据链路协议》
- 2025年中国无铅压电粉末材料行业市场分析及投资价值评估前景预测报告
- 网信安全培训总结课件
- 高分辨率内窥成像-洞察与解读
- 2025国考鞍山市税收征管岗位行测必刷题及答案
- 2025国考白山市外交业务岗位行测高频考点及答案
- 2025国考太原市食品药品监管岗位申论高频考点及答案
- 2025年妇产科副高护理答辩题库及答案
- 2025年枣庄滕州市青年就业见习(1540人)考试参考试题及答案解析
- 安全生产管理制度全集
- 江浙皖高中(县中)发展共同体2025-2026学年高三上学期10月联考物理试题(含答案)
- 资阳发展投资集团有限公司第二轮一般员工市场化招聘笔试历年参考题库附带答案详解
- 安徽省c证安全生产模拟考试题库及答案解析
- 心理健康教育课程名词解释大全
- 2025年全国中小学生天文知识竞赛试题库(含答案)
- 研究会管理办法
- 2025年时事政治考试100题(含参考答案)
- Keil5、Proteus8的使用.PPT
评论
0/150
提交评论