HTML5先行者高级交流群

欢迎加入学习讨论
专注前端,专注网页设计制作及网站开发项目 - (低价承接网站开发项目) QQ:370158739加入收藏RSS
如何在ASP中使用mySQL_ASP教程_编程技术
2013-12-20 09:14:17
[小 大]
已经帮助:人解决问题
Using A mySQL Databases
by Ben O'Neill
Databases are the best way to keep your web site up-to-date and dynamic. Databases are used these days by
thousands of web sites. They are used for storing news and general information. Web sites like the ASP
Index (www.aspin.com) are run on large databases. Databases make a web site easy to update and once you
have the base script, to add, remove and modify things in a database is very easy.
To start you need to know how to connect to a database. ASP can connect to virtually any type, from
Microsoft Access to SQL. In this example I'll be using mySQL and OLE DB to connect to it.
mySQL can be downloaded from the mySQL web site (www.mysql.com). You will also need the provider used to
connect to it, also available from the mySQL web site.
You may be asking what's OLE DB? I'm used to ODBC and DSN. OLE DB is faster and more stable. It's almost
exactly the same.
First we need to connect to the database, because it's a mySQL database you also need to supply a database
name. (in mySQL you can have mulitple databases on the same SQL server.)
<%
strConnection = "driver={MySQL};server=localhost;uid=benoneill;pwd=mypassword;database=databasename"
Set adoDataConn = Server.CreateObject("ADODB.Connection")
adoDataConn.Open strConnection
%>
And now we've connected. Let's pretend we've got a big list of lots and lots of email addresses, here's
the contents of our database, it allows me to show you how it works better.
Table Name: emailadds
name ? ?emailadd
------------------------------------------------------
Ben ? ?sheepcow@planetunreal.com
Fred ?freddy@thebigisp.com
Ben Harding ?benharding@hisisp.com
Dave Geralding ?daveg@mymail.com
Now we have the database open let's run a query to list and output all the names and email address in a
nice easy to view table.
<%
?strQuery = "SELECT * FROM emailadds"
?Set rsEmailData = adoDataConn.Execute(strQuery)
?If Not rsEmailData.BOF Then
%>
<TABLE>
?/span><TR>