让ASP搭配MYSQL
程序员文章站
2024-01-28 19:47:10
让asp搭配mysql 所需要工具 mysql-4.1.11-win32 myodbc-3.51.1...
让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_machine\software\odbc\odbcinst.ini\myodbc driver]
"usagecount"=dword:00000002
"driver"="c:\\windows\\system\\myodbc.dll"
"setup"="c:\\windows\\system\\myodbc.dll"
"sqllevel"="1"
"fileusage"="0"
"driverodbcver"="03.51"
"connectfunctions"="yyy"
"apilevel"="1"
"cptimeout"="120"
[hkey_local_machine\software\odbc\odbcinst.ini\odbc drivers]
"myodbc driver"="installed"
-------------------------------------------------------------------
建立asp文件链接数据库
例子如下
windows dsn name: 所要建立dsn的名称
mysql host (name or ip):mysql服务器的名称或者是ip地址,通常填localhost
mysql database name: admin
database: admin
password: 000000
port(if not 3306):
sql command on connect:
下面两种链接数据库的asp代码
1. 使用dsn
<%
strconnection = "dsn=admin;driver={myodbd driver};server=localhost;uid=root;pwd=000000;database=admin"
set adodataconn = server.createobject("adodb.connection")
adodataconn.open strconnection
strquery = "select * from user"
set rs = adodataconn.execute(strquery)
if not rs.bof then
%>
<table>
<tr>
<td<b>username</b></td>
<td><b>password</b></td>
</tr>
<%
do while not rs.eof
%>
<tr>
<td><%=rs("username")%></td>
<td><%=rs("password")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
<%
else
response.write("sorry, no data found.")
end if
rs.close
adodataconn.close
set adodataconn = nothing
set rsemaildata = nothing
%>
2. 不使用dsn
<%
strconnection="defaultdir=;driver={myodbc driver};database=admin"
set adodataconn = server.createobject("adodb.connection")
adodataconn.open strconnection
strquery = "select * from user"
set rs = adodataconn.execute(strquery)
if not rs.bof then
%>
<table>
<tr>
<td<b>username</b></td>
<td><b>password</b></td>
</tr>
<%
do while not rs.eof
%>
<tr>
<td><%=rs("username")%></td>
<td><%=rs("password")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
<%
else
response.write("sorry, no data found.")
end if
rs.close
adodataconn.close
set adodataconn = nothing
set rsemaildata = nothing
%>
所需要工具
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_machine\software\odbc\odbcinst.ini\myodbc driver]
"usagecount"=dword:00000002
"driver"="c:\\windows\\system\\myodbc.dll"
"setup"="c:\\windows\\system\\myodbc.dll"
"sqllevel"="1"
"fileusage"="0"
"driverodbcver"="03.51"
"connectfunctions"="yyy"
"apilevel"="1"
"cptimeout"="120"
[hkey_local_machine\software\odbc\odbcinst.ini\odbc drivers]
"myodbc driver"="installed"
-------------------------------------------------------------------
建立asp文件链接数据库
例子如下
windows dsn name: 所要建立dsn的名称
mysql host (name or ip):mysql服务器的名称或者是ip地址,通常填localhost
mysql database name: admin
database: admin
password: 000000
port(if not 3306):
sql command on connect:
下面两种链接数据库的asp代码
1. 使用dsn
<%
strconnection = "dsn=admin;driver={myodbd driver};server=localhost;uid=root;pwd=000000;database=admin"
set adodataconn = server.createobject("adodb.connection")
adodataconn.open strconnection
strquery = "select * from user"
set rs = adodataconn.execute(strquery)
if not rs.bof then
%>
<table>
<tr>
<td<b>username</b></td>
<td><b>password</b></td>
</tr>
<%
do while not rs.eof
%>
<tr>
<td><%=rs("username")%></td>
<td><%=rs("password")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
<%
else
response.write("sorry, no data found.")
end if
rs.close
adodataconn.close
set adodataconn = nothing
set rsemaildata = nothing
%>
2. 不使用dsn
<%
strconnection="defaultdir=;driver={myodbc driver};database=admin"
set adodataconn = server.createobject("adodb.connection")
adodataconn.open strconnection
strquery = "select * from user"
set rs = adodataconn.execute(strquery)
if not rs.bof then
%>
<table>
<tr>
<td<b>username</b></td>
<td><b>password</b></td>
</tr>
<%
do while not rs.eof
%>
<tr>
<td><%=rs("username")%></td>
<td><%=rs("password")%></td>
</tr>
<%
rs.movenext
loop
%>
</table>
<%
else
response.write("sorry, no data found.")
end if
rs.close
adodataconn.close
set adodataconn = nothing
set rsemaildata = nothing
%>