资源描述:
《毕业论文外文翻译-通过PHP访问MySQL》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、原文: GettingPHPtoTalktoMySQlNowthatyou’recomfortableusingtheMySQLclienttoolstomanipulatedatainthedatabase,youcanbeginusingPHPtodisplayandmodifydatafromthedatabase.PHPhasstandardfunctionsforworkingwiththedatabase.First,we’regoingtodiscussPHP’sbuilt-indatabasefunctions.We’llalsos
2、howyouhowtousetheThePHPExtensionandApplicationRepository(PEAR)databasefunctionsthatprovidetheabilitytousethesamefunctionstoaccessanysupporteddatabase.Thistypeofflexibilitycomesfromaprocesscalledabstraction.Inprogramminginterfaces,abstractionsimplifiesacomplexinteraction.Itworks
3、byremovinganynonessentialpartsoftheinteraction,allowingyoutoconcentrateontheimportantparts.PEAR’sDBclassesareonesuchdatabaseinterfaceabstraction.Theinformationyouneedtologintoadatabaseisreducedtothebareminimum.ThisstandardformatallowsyoutointeractwithMySQL,aswellasotherdatabase
4、susingthesamefunctions.Similarly,otherMySQL-specificfunctionsarereplacedwithgenericonesthatknowhowtotalktomanydatabases.Forexample,theMySQL-specificconnectfunctionis:mysql_connect($db_host,$db_username,$db_password);versusPEAR’sDBconnectfunction:$connection=DB::connect("mysql:/
5、/$db_username:$db_password@$db_host/$db_database");Thesamebasicinformationispresentinbothcommands,butthePEARfunctionalsospecifiesthetypeofdatabasestowhichtoconnect.YoucanconnecttoMySQLorothersupporteddatabases.We’lldiscussbothconnectionmethodsindetail.Inthischapter,you’lllearnh
6、owtoconnecttoaMySQLserverfromPHP,howtousePHPtoaccessandretrievestoreddata,andhowtocorrectlydisplayinformationtotheuser.TheProcessThebasicstepsofperformingaquery,whetherusingthemysqlcommand-linetoolorPHP,arethesame:•Connecttothedatabase.•Selectthedatabasetouse.•BuildaSELECTstate
7、ment.•Performthequery.•Displaytheresults.We’llwalkthrougheachofthesestepsforbothplainPHPandPEARfunctions.ResourcesWhenconnectingtoaMySQLdatabase,youwillusetwonewresources.Thefirstisthelinkidentifierthatholdsalloftheinformationnecessarytoconnecttothedatabaseforanactiveconnection
8、.Theotherresourceistheresultsresource.Itcontainsallinf