问题
I have had to move on of my old classic ASP projects to a new host, and I'm having problems connecting to their MySQL server.
I have attached below the script I used with the old host which now errors
Data source name not found and no default driver specified
After a bit of digging it seems I have to change the driver to {MySQL ODBC 5.3 Unicode Driver}
but it still errors. It seems to point to the cursor/lock type but I have used all option with no success.
ODBC driver does not support the requested properties.
<%
Dim Conn
Dim Rs
Dim sql
Set Conn = Server.CreateObject("ADODB.Connection")
Set Rs = Server.CreateObject("ADODB.Recordset")
Conn.Open "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=xxx; PORT=xxx; DATABASE=xxx; UID=xxx; PASSWORD=xxx; OPTION=3"
sql= "SELECT * FROM table;"
Rs.CursorType = 2
Rs.LockType = 3
Rs.Open sql, Conn
Rs.AddNew
Rs.Fields("database") = Request.Form("form")
Rs.Update
Rs.Close
Set Rs = Nothing
Set Conn = Nothing
%>
回答1:
You don't need this to insert a record. Instead, use plain SQL which should be supported by all database drivers:
Dim oCommand
Const adInteger = 3
Const adDate = 7
Const adVarChar = 200
sql = "Insert Into table (database) Values (?)"
Set oCommand = Server.Createobject("ADODB.Command")
Set oCommand.ActiveConnection = Conn
oCommand.CommandText = sql
oCommand.Parameters.Append(oCommand.CreateParameter("database", adVarChar, , 512, Request.Form("form")) )
oCommand.Execute
This is indeed bit more to write, but should preserve all the benefits of the other way (e.g. SQL Injections attack protection) and not being dependant on specific drivers.
来源:https://stackoverflow.com/questions/39988294/classic-asp-adding-records-to-mysql