How do I connect to a MySQL database from Classic ASP?
Posted by Support on 31 July 2009 10:44 AM
MySQL is a perfect database solution for small to medium websites. If your backend MySQL database is well optimized and properly structured it can serve thousands of visitors daily, without degrading your server performance. If you have an error about the ODBC 5.1 driver then replace {MySQL ODBC 5.1 Driver} with {MySQL ODBC 3.51 Driver}, below.

<%
Dim sConnection, objConn , objRS

sConnection = "DRIVER={MySQL ODBC 5.1 Driver}; SERVER=ServerIP; DATABASE=Your_Mysql_DB_name; UID=Your_Mysql_Username;PASSWORD=Your_Mysql_Password; OPTION=3"

Set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open(sConnection)

Set objRS = objConn.Execute("SELECT FirstName, LastName FROM tblUsers")


While Not objRS.EOF
Response.Write objRS.Fields("LastName") & ", " & objRS.Fields("FirstName") & "<br>"
Response.Write & " "
objRS.MoveNext
Wend

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
(652 vote(s))
Helpful
Not helpful

Comments (0)