ASP如何连接mysql数据库?
展开全部
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%Response.Buffer=True%>
<%
IsSqlDataBase=0 '定义数据库类别,0为Access数据库,1为SQL数据库
If IsSqlDataBase=0 Then
'''''''''''''''''''''''''''''' Access数据库 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
datapath ="include/" '数据库目录的相对路径
datafile ="data.mdb" '数据库的文件名
Connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.mapPath(datapath&datafile)&""
SqlNowString="Now()"
SqlChar="'"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
'''''''''''''''''''''''''''''' SQL数据库 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SqlLocalName ="(local)" '连接IP [ 本地用 (local) 外地用IP ]
SqlUsername ="sa" '用户名
SqlPassword ="1" '用户密码
SqlDatabaseName="MyDBname" '数据库名
ConnStr = "Provider=Sqloledb;User ID=" & SqlUsername & "; Password=" & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source=" & SqlLocalName & ";"
SqlNowString="GetDate()"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End If
On Error Resume Next
Set conn=Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"
Response.End
End If
On Error GoTo 0
%>
<%Response.Buffer=True%>
<%
IsSqlDataBase=0 '定义数据库类别,0为Access数据库,1为SQL数据库
If IsSqlDataBase=0 Then
'''''''''''''''''''''''''''''' Access数据库 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''
datapath ="include/" '数据库目录的相对路径
datafile ="data.mdb" '数据库的文件名
Connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.mapPath(datapath&datafile)&""
SqlNowString="Now()"
SqlChar="'"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
'''''''''''''''''''''''''''''' SQL数据库 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
SqlLocalName ="(local)" '连接IP [ 本地用 (local) 外地用IP ]
SqlUsername ="sa" '用户名
SqlPassword ="1" '用户密码
SqlDatabaseName="MyDBname" '数据库名
ConnStr = "Provider=Sqloledb;User ID=" & SqlUsername & "; Password=" & SqlPassword & "; Initial Catalog = " & SqlDatabaseName & "; Data Source=" & SqlLocalName & ";"
SqlNowString="GetDate()"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End If
On Error Resume Next
Set conn=Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then
err.Clear
Set Conn = Nothing
Response.Write "数据库连接出错,请检查连接字串。"
Response.End
End If
On Error GoTo 0
%>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询