经典ASP将记录添加到MySQL [英] Classic ASP adding records to MySQL

查看:167
本文介绍了经典ASP将记录添加到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不将旧的经典ASP项目转移到新主机上,并且在连接到他们的MySQL服务器时遇到问题.

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

经过一番挖掘,看来我不得不将驱动程序更改为{MySQL ODBC 5.3 Unicode Driver},但仍然出错.似乎指向了游标/锁定类型,但是我使用了all选项,但没有成功.

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驱动程序不支持请求的属性.

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
%>

推荐答案

您不需要此插入记录.相反,请使用所有数据库驱动程序都应支持的普通SQL:

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

这确实要写得多,但是应该保留其他方式的所有优点(例如SQL注入攻击防护),并且不依赖于特定的驱动程序.

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.

这篇关于经典ASP将记录添加到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆