Friday, May 05, 2006

ASP and MySQL

Seems there is some interest in running MySQL as a backend for (classic) ASP based sites, at least looking at recent posts on DevShed forums.
As questions are quite similar and I've not found a good ASP+MySQL tutorial on the web I'm posting a short example here
Here is my snippet:

  1. dim adoConn
  2. dim adoRS
  3. set adoConn = Server.CreateObject("ADODB.Connection")
  4. set adoRS = Server.CreateObject("ADODB.Recordset")
  5. adoConn.CursorLocation = 3
  6. 'adUseClient
  7. adoConn.Open "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=users;UID=root;PWD=; OPTION=16427"
  8. adoRS.ActiveConnection = adoConn
  9. if adoConn.errors.count = 0 then
  10. adoRS.Open "Select ...", adoConn
  11. .....
  12. adoRS.Close
  13. else
  14. response.write ("ERROR: Couldn't connect to database")
  15. end if
  16. adoConn.Close
  17. Set adoRS = nothing
  18. Set adoConn = nothing


And here is an excellent date conversion function by Devshed user.
Note that Mike Hillyer's writings about vb and MySQL are an excellent resource!!

No comments: