资源描述:
《毕业论文外文翻译-通过php访问mysql》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、原文:GettingPHPtoTalktoMySQlNowthatyou^recomfortableusingtheMySQLclienttoolstomanipulatedatainthedatabase,youcanbeginusingPHPtodisplayandmodifydatafromthedatabase.PHPhasstandardfunctionsforworkingwiththedatabase.First,we9regoingtodiscussPHP,sbuilt-indatabasefunctions.We
2、TIalsoshowyouhowtousetheThePHPExtensionandApplicationRepository(PEAR)databasefunctionsthatprovidetheabilitytousethesamefunctionstoaccessanysupporteddatabase.Thistypeofflexibil让ycomesfromaprocesscalledabstraction.Inprogramminginterfaces,abstractionsimplifiesacomplexint
3、eraction.Itworksbyremovinganynonessentialpartsoftheinteraction,allowingyoutoconcentrateontheimportantparts.PEAR'sDBclassesareonesuchdatabaseinterfaceabstraction.Theinformationyouneedtologintoadatabaseisreducedtothebareminimum.ThisstandardformatallowsyoutointeractwithM
4、ySQL,aswellasotherdatabasesusingthesamefunctions.Similarly,otherMySQL-specificfunctionsarereplacedwithgenericonesthatknowhowtotalktomanydatabases.Forexample,theMySQL-specificconnectfunctionis:mysql_connect($db_host,$db_username,$db_password);versusPEARLSDBconnectfunct
5、ion:Sconnection=DB::connect(Hmysql://$db_username:$db_password@$db_host/$db_databasen);Thesamebasicinformationispresentinbothcommands,butthePEARfunctionalsospecifiesthetypeofdatabasestowhichtoconnect.YoucanconnecttoMySQLorothersupporteddatabases.Welldiscussbothconnect
6、ionmethodsindetail.Inthischapter,yoiflllearnhowtoconnecttoaMySQLserverfromPHP,howtousePHPtoaccessandretrievestoreddata,andhowtocorrectlydisplayinformationtotheuser.TheProcessThebasicstepsofperformingaquery,whetherusingthemysqlcommand-linetoolorPHP,arethesame:•Connectt
7、othedatabase.•Selectthedatabasetouse.•BuildaSELECTstatement.•Performthequery.•Displaytheresults.WeTIwalkthrougheachofthesestepsforbothplainPHPandPEARfunctions-ResourcesWhenconnectingtoaMySQLdatabase,youwillusetwonewresources.Thefirstisthelinkidentifierthatholdsallofth
8、einformationnecessarytoconnecttothedatabaseforanactiveconnection.Theotherresourceistheresultsresource.Itcontainsallinformati