网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.建立三层结构的ASP应用程序.
.asp+oracle分页程序类(XDOWNPAG.
.在PPC上实现编译ASP.
.automation服务器不能创建对象.
.连接各种数据库的代码的总结.
.如何更好更快的debug.
.一个socket组件及其调用方法.
.从数据库中动态选取下拉列表的方.
.asp+的页面指示标识.
.asp中对ip进行过滤限制函数.
.在HTML页面中实现点击数统计.
.让ASP也可以连接MYSQL .
.用ASP语言实现对SQL SERVER 数据.
.连接WEB数据库的ADO性能提高技巧.
.实现让每句话的头一个字母都大写.
.Microsoft IIS 真的如此「不安全.
.转换文本为超联和Email格式的代码.
.动态网站首页的静态生成方法.
.如何使用asp创建dsn.
.通过asp入侵web server,窃取文件.

如何在ASP中使用mySQL

发表日期:2000-8-6


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>

牋 <TD<b>Name</b></TD>

牋 <TD><b>Email Address</b></TD>

?/span></TR>



<%

?Do While Not rsEmailData.EOF

%>



?/span><TR>

牋 <TD><%=rsEmailData("name").Value %></TD>

牋 <TD><%=rsEmailData("emailadd").Value %></TD>

?/span></TR>



<%

牋?rsEmailData.MoveNext

?Loop



%>



</TABLE>



<%

?Else



牋? Response.Write("Sorry, no email addresses found.")



?End If

%>





There we go. If no records are found then it says "Sorry, no email addresses found".



That query is simple enough, it tells the database to get (SELECT) all the records and all the fields from
the table named emailadds.



How about we make it only show people with the name "ben" somewhere in their name, simple change the query
to this:



SELECT * FROM emailadds WHERE name LIKE '%ben%'


That query would return only 2 records, Ben and Ben Harding.



It's important you use single quotes ('), because double quotes won't work. You can also be very selective
and do:



SELECT * FROM emailadds WHERE name='Ben'


That query would only return Ben, not Fred or Ben Harding, or Dave Geralding.



After using databases you should always clear up. Close the database and the record set, and set them to
nothing so that the memory used by them is regained, do this by writing this:



<%

?rsEmailData.Close

?adoDataConn.Close



?Set adoDataConn = Nothing

?Set rsEmailData = Nothing

%>
上一篇:使用命名管道访问SQL Server 人气:11467
下一篇:ASP编程中15个非常有用的例子(一) 人气:12836
浏览全部mySQL的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐