Yesky首页| 产品报价| 行情| 手机 | 数码 | 笔记本 | 台式机 | DIY硬件 | 外设 | 网络 | 数字家庭 | 评测 | 软件 | e时代 | 游戏 | 图片 | 壁纸 | 群乐 | 社区 | 博客 | 下载
您现在的位置: 天极网 > 开发频道 > web开发 > 如何在ASP中连接MySQL数据库
全文

如何在ASP中连接MySQL数据库

2004-04-06 14:29 作者: 明水轩工作室 出处: yesky 责任编辑:>方舟
  三、ASP和数据库的连接

  下面是我测试过的,连接MySQL的源代码,连接的库名为mm,表名为my,表中有两个字段 name 和 sex。

<html>
<head>
 <title>MySQL连接测试</title>
 <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
 <%
  strconnection="dsn=mysqltest;
  driver={mysql odbc 3.51 driver};
  server=填入服务器地址;uid=用户名;pwd=密码;database=mm"
  ‘连接字符串,dsn就是我们设置的数据源标识符
  注意driver我们刚才在设置系统DSN的时候提过。
 
  set conn = server.createobject("adodb.connection")
  conn.open strconnection
  sql = "select * from my" ‘SQL查询语句
  set rs = conn.execute(sql)
  if not rs.bof then

 %>

 <table width="167">
 <tr>
  <td width="76"><b>name</b></td>
  <td width="79"><b>sex</b></td>
 </tr>
 <%
  do while not rs.eof
 %>
 <tr>
  <td><%=rs("name")%></td> ‘name字段
  <td><%=rs("sex")%></td> ‘sex字段
 </tr>
 <%
   rs.movenext
  loop
 %>
 </table>

 <%
  else
   response.write("sorry, no data found.")
  end if
  rs.close
  conn.close
  set conn = nothing
  set rs = nothing
 %>
</body>
</html>
共3页。 9 7 1 2 3
共3页。 9 1 2 3
网友关注
最新上市
编辑推荐
文章阅读排行
周排行
月排行
欢迎订阅天极网RSS聚合资讯:http://www.yesky.com/index.xml