让ASP搭配MYSQL
所需要工具
mysql-4.1.11-win32
myodbc-3.51.11-1-dll
myodbc-3.51.11-1-win
mysqlcc-0.9.4-win32
-------------------------------------------------------------------
注册文件Mydbc.reg
REGEDIT4
[HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INImyodbcdriver]
"UsageCount"=dword:00000002
"Driver"="C:WINDOWSSystemmyodbc.dll"
"Setup"="C:WINDOWSSystemmyodbc.dll"
"SQLLevel"="1"
"FileUsage"="0"
"DriverODBCVer"="03.51"
"ConnectFunctions"="YYY"
"APILevel"="1"
"CpTimeout"="120"
[HKEY_LOCAL_MACHINESOFTWAREODBCODBCINST.INIODBCDrivers]
"myodbcdriver"="installed"
-------------------------------------------------------------------
建立ASP文件链接数据库
例子如下
WindowsDSNname:所要建立DSN的名称
MysqlHost(nameorip):Mysql服务器的名称或者是IP地址,通常填localhost
Mysqldatabasename:admin
Database:admin
password:000000
Port(ifnot3306):
SQLcommandonconnect:
下面两种链接数据库的ASP代码
1.使用DSN
<%
strConnection="dsn=admin;driver={myodbddriver};server=localhost;uid=root;pwd=000000;database=admin"
SetadoDataConn=Server.CreateObject("ADODB.Connection")
adoDataConn.OpenstrConnection
strQuery="SELECT*FROMuser"
Setrs=adoDataConn.Execute(strQuery)
IfNotrs.BOFThen
%>
<TABLE>
<TR>
<TD<b>username</b></TD>
<TD><b>password</b></TD>
</TR>
<%
DoWhileNotrs.EOF
%>
<TR>
<TD><%=rs("username")%></TD>
<TD><%=rs("password")%></TD>
</TR>
<%
rs.MoveNext
Loop
%>
</TABLE>
<%
Else
Response.Write("Sorry,nodatafound.")
EndIf
rs.Close
adoDataConn.Close
SetadoDataConn=Nothing
SetrsEmailData=Nothing
%>
2.不使用DSN
<%
strconnection="DefaultDir=;Driver={myodbcdriver};database=admin"
SetadoDataConn=Server.CreateObject("ADODB.Connection")
adoDataConn.OpenstrConnection
strQuery="SELECT*FROMuser"
Setrs=adoDataConn.Execute(strQuery)
IfNotrs.BOFThen
%>
<TABLE>
<TR>
<TD<b>username</b></TD>
<TD><b>password</b></TD>
</TR>
<%
DoWhileNotrs.EOF
%>
<TR>
<TD><%=rs("username")%></TD>
<TD><%=rs("password")%></TD>
</TR>
<%
rs.MoveNext
Loop
%>
</TABLE>
<%
Else
Response.Write("Sorry,nodatafound.")
EndIf
rs.Close
adoDataConn.Close
SetadoDataConn=Nothing
SetrsEmailData=Nothing
%>