I'll take a stab at it. It's been a while since I used vbscript (on a .asp page) to connect to MySQL.
The MySQL_STRING is exactly as I used it (but I had the old ODBC 3.51 driver, I've changed the name for the new driver)
Everthing else is just as I used it. User, password, and dbname will need to be adjusted to your use.
)<%
Dim MySQL_STRING
MySQL_STRING = "Driver={MySQL ODBC 5.1 Driver}; Server=localhost; Port=3306; Option=2; Socket=; Stmt=; Database=dbname; Uid=user; Pwd=password;"
dim adoConn
dim adoRS
dim col1
dim col2
set adoConn = Server.CreateObject("ADODB.Connection")
set adoRS = Server.CreateObject("ADODB.Recordset")
adoConn.Open MySQL_STRING
adoRS.ActiveConnection = adoConn
adoRS.Source = "SELECT col1, col2 from mytable where id = 1" 'here's your SQL query
adoRS.CursorLocation = 3 'adUseClient
adoRS.Open
if (adoRS.RecordCount < 1) then
' no records
else ' there is at least one record
col1 = adoRS.Fields("col1")
col2 = adoRS.Fields("col2")
end if
adoRS.Close
set adoRS = nothing
adoConn.Close
set adoConn = nothing
%>
You get the idea?
Your database will need to be on a MySQL server where your website can access it, usually the same place as where your website is hosted (localhost).
If your MySQL is on a different host, then you'll need to change the hostname from 'localhost' to 'whatever.com' and the Mysql database will need to allow connections from your mysql
user@your.webhost.com.
For info on how to use vbscript, search the microsoft website for VBscript user guide, in particular ADO.
Good luck,
Barry.
Edited 1 time(s). Last edit at 10/16/2010 05:34AM by Barry Galbraith.