Connect to MySQL from ASP

This section contains the codes and resources related to Classic ASP and ASP.net languages.

Connect to MySQL from ASP

Postby MT Shahzad on March 21st, 2008, 7:52 pm

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. In this article I'll show you how to connect to MySQL database from ASP. You will have to install MySQL ODBC Driver-MyODBC 3.51 if you don't have it on your server yet. You can download it here: http://www.mysql.com/downloads/api-myodbc-3.51.html

Code: Select all
<%
Dim sConnection, objConn , objRS

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)

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
%>
MT Shahzad
Web/Software Developer
http://mts.sw3solutions.com
User avatar
MT Shahzad
Site Admin
 
Posts: 300
Joined: February 29th, 2008, 8:11 am
Location: Muridke, Pakistan

Return to ASP / ASP.net

Who is online

Users browsing this forum: No registered users and 0 guests

cron