asp的配套数据库是microsoft access,不过也可以连接mysql
连接之前需要配置一下,详情可以见该博客
https://blog.csdn.net/zzx2016zzx/article/details/81024287
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<%@ language="VBSCRIPT" CODEPAGE="65001"%>
<%
set conn=Server.Createobject("adodb.Connection")
str="dsn=conn;Driver={mysql driver};server=127.0.0.1;uid=root;pwd=HZPLSZL233;database=typemoon"
' 连接数据库
conn.open(str)
'从数据库中读取信息
sql = "select * from charactors"
set rs = conn.execute(sql)
’判断数据库是否为空,bof表示第一条数据之前,如果游标停在此处,表示数据库为空,与之相对的是.eof表示最后一条信息之后,代表读取结束
if rs.bof then
Response.Write("ERROR: ")
else
%>
<table>
<tr>
<td width="50px">name</td>
<td width="100px">title</td>
<td width="500px">content</td>
<td width="500px">picture</td>
</tr>
<%
do while not rs.eof
%>
<tr>
<td><%=rs("ty_name")%></td>
<td><%=rs("ty_title")%></td>
<td><script type="text/javascript" charset="utf-8" async defer>
document.write(JSON.stringify(<%=rs("ty_content")%>).replace(/\\/g,""));
</script></td>
<td><%=rs("ty_picture")%></td>
</tr>
<%
rs.movenext
loop
end if
rs.close
set rs = nothing
conn.close
set conn=nothing
%>
</table>
</body>
</html>