|
如何在ASP中连接MySQL 数据库(2) 码;database=mm" ‘连接字符串,dsn就是我们设置的数据源标识符 注意driver我们刚才在设置系统DSN的时候提过。 试验发现,dsn=mysqltest;就已经可以正常连接数据库,原因很简单就是我们已经在ODBC中完成了和MySQL的各项连接工作了。 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>
|