|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
对于中小型web应用来说,php有很强的竞争力,linux+apache+mysql+php(lamp)的组合几乎可以胜任绝大多数网站的解决方案,对于大型应用来讲,对于系统架构要求更高,需要有成熟的框架支持,jsp的struts是个不错的框架,国内介绍它的资料也非常多,应用逐渐广泛起来。asp就不用说了,UsingAmySQLDatabases
byBenONeill
Databasesarethebestwaytokeepyourwebsiteup-to-dateanddynamic.Databasesareusedthesedaysby
thousandsofwebsites.Theyareusedforstoringnewsandgeneralinformation.WebsitesliketheASP
Index(www.aspin.com)arerunonlargedatabases.Databasesmakeawebsiteeasytoupdateandonceyou
havethebasescript,toadd,removeandmodifythingsinadatabaseisveryeasy.
Tostartyouneedtoknowhowtoconnecttoadatabase.ASPcanconnecttovirtuallyanytype,from
MicrosoftAccesstoSQL.InthisexampleIllbeusingmySQLandOLEDBtoconnecttoit.
mySQLcanbedownloadedfromthemySQLwebsite(www.mysql.com).Youwillalsoneedtheproviderusedto
connecttoit,alsoavailablefromthemySQLwebsite.
YoumaybeaskingwhatsOLEDB?ImusedtoODBCandDSN.OLEDBisfasterandmorestable.Itsalmost
exactlythesame.
Firstweneedtoconnecttothedatabase,becauseitsamySQLdatabaseyoualsoneedtosupplyadatabase
name.(inmySQLyoucanhavemulitpledatabasesonthesameSQLserver.)
<%
strConnection="driver={MySQL};server=localhost;uid=benoneill;pwd=mypassword;database=databasename"
SetadoDataConn=Server.CreateObject("ADODB.Connection")
adoDataConn.OpenstrConnection
%>
Andnowweveconnected.Letspretendwevegotabiglistoflotsandlotsofemailaddresses,heres
thecontentsofourdatabase,itallowsmetoshowyouhowitworksbetter.
TableName:emailadds
name??emailadd
------------------------------------------------------
Ben??sheepcow@planetunreal.com
Fred?freddy@thebigisp.com
BenHarding?benharding@hisisp.com
DaveGeralding?daveg@mymail.com
Nowwehavethedatabaseopenletsrunaquerytolistandoutputallthenamesandemailaddressina
niceeasytoviewtable.
<%
?strQuery="SELECT*FROMemailadds"
?SetrsEmailData=adoDataConn.Execute(strQuery)
?IfNotrsEmailData.BOFThen
%>
<TABLE>
?/span><TR>
<TD<b>Name</b></TD>
<TD><b>EmailAddress</b></TD>
?/span></TR>
<%
?DoWhileNotrsEmailData.EOF
%>
?/span><TR>
<TD><%=rsEmailData("name").Value%></TD>
<TD><%=rsEmailData("emailadd").Value%></TD>
?/span></TR>
<%
?rsEmailData.MoveNext
?Loop
%>
</TABLE>
<%
?Else
?Response.Write("Sorry,noemailaddressesfound.")
?EndIf
%>
Therewego.Ifnorecordsarefoundthenitsays"Sorry,noemailaddressesfound".
Thatqueryissimpleenough,ittellsthedatabasetoget(SELECT)alltherecordsandallthefieldsfrom
thetablenamedemailadds.
Howaboutwemakeitonlyshowpeoplewiththename"ben"somewhereintheirname,simplechangethequery
tothis:
SELECT*FROMemailaddsWHEREnameLIKE%ben%
Thatquerywouldreturnonly2records,BenandBenHarding.
Itsimportantyouusesinglequotes(),becausedoublequoteswontwork.Youcanalsobeveryselective
anddo:
SELECT*FROMemailaddsWHEREname=Ben
ThatquerywouldonlyreturnBen,notFredorBenHarding,orDaveGeralding.
Afterusingdatabasesyoushouldalwaysclearup.Closethedatabaseandtherecordset,andsetthemto
nothingsothatthememoryusedbythemisregained,dothisbywritingthis:
<%
?rsEmailData.Close
?adoDataConn.Close
?SetadoDataConn=Nothing
?SetrsEmailData=Nothing
%>
Windows本身的所有问题都会一成不变的也累加到了它的身上。安全性、稳定性、跨平台性都会因为与NT的捆绑而显现出来; |
|