asp教程連接mysql教程數據庫教程幾款代碼
strconnection = "dsn=hc188;driver={myodbd driver};server=localhost;uid=root;pwd=;database=hc188"
set adodataconn = server.createobject("adodb.connection")
adodataconn.open strconnection
方法二
strconnection="dsn=MySQL(和PHP搭配之最佳組合)test;
driver={MySQL(和PHP搭配之最佳組合) odbc 3.51 driver};
server=填入服務器地址;uid=用戶名;pwd=密碼;database=mm";
看個實例
Dim sConnection, objConn , objRS
'SERVER為數據庫主機名(本地主機用localhost,遠程用IP地址);DATABASE為數據庫名;UID為用戶名;PASSWORD為密碼
sConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=Your_Mysql_DB; UID=mysql_username;PASSWORD=mysql_password; OPTION=3"
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open(sConnection)
'以下SQL語句為示例語句,請根據實際情況修改
Set objRS = objConn.Execute("SELECT FirstName, LastName FROM tblUsers")
While Not objRS.EOF 'while...wend循環,用於讀取所有的信息
Response.Write objRS.Fields("LastName") & ", " & objRS.Fields("FirstName") & "《br》"
objRS.MoveNext '記錄集指針下移
Wend
objRS.Close '關閉記錄集
Set objRS = Nothing '清空記錄集,釋放內存
objConn.Close '關閉數據庫鏈接
Set objConn = Nothing '清空數據庫鏈接,釋放內存
%>
asp和mysql連接目前有兩個辦法:一個是使用組件,常用的是mysqlx收費組件;二就是使用myodbc來連接