MySQL 和 ADO - 无望了吗?
整个周末都在撕扯头发并谷歌搜索。我正在疯狂地将 ASP 站点转换为使用 MySQL。我是否正确地认为尝试使用记录集命令通过 ODBC 将数据传入和传出 MySQL 会是错误的树,而应该只使用 MySQL 过程?如果是这样,我将面临一场噩梦,我认为必须弄清楚如何捕获返回的值。
抱歉,如果这听起来非常无知,但不知道该转向哪里。
细节:
Set SConn = createobject("ADODB.Connection")
conn.open = "DRIVER={MySQL ODBC 5.1 Driver};"_
& "SERVER=" & SQLServer & ";"_
& "DATABASE=" & SQLDbase & ";"_
& "UID=" & SQLUser & ";PWD=" & SQLPW & "; OPTION=35;"
SQL = "SELECT tblNodes.SingleSiteChildID "
SQL = SQL & "FROM tblNodes "
SQL = SQL & "WHERE (((tblNodes.NodeID)=" & m_lngNodeID & "));"
set RS=server.CreateObject("adodb.Recordset")
RS.CursorType = 1
RS.LockType = 2
RS.Open SQL, conn
With RS
If not .Fields("SingleSiteChildID") >0 or isnull(.Fields("SingleSiteChildID")) then
If m_lngChildCount>0 then
.Fields("SingleSiteChildID")=0
m_lngSingleSiteChildID=0
Else
.Fields("SingleSiteChildID")=null
m_lngSingleSiteChildID=null
End if
.UPDATE
End if
END WITH
RS.Close
Set RS = Nothing
Set conn = Nothing
End Sub
Tearing hair out and googling all weekend. I am frantically converting an ASP site to use MySQL. Am I correct in thinking that I would be barking up the wrong tree to try to use recordset commands to get data in and out of MySQL via ODBC and should only use MySQL procedures? If so I face a nightmare, I think as have then to work out how to capture the returned values.
Sorry if this sounds hideously ignorant, but no idea where to turn.
DETAILS:
Set SConn = createobject("ADODB.Connection")
conn.open = "DRIVER={MySQL ODBC 5.1 Driver};"_
& "SERVER=" & SQLServer & ";"_
& "DATABASE=" & SQLDbase & ";"_
& "UID=" & SQLUser & ";PWD=" & SQLPW & "; OPTION=35;"
SQL = "SELECT tblNodes.SingleSiteChildID "
SQL = SQL & "FROM tblNodes "
SQL = SQL & "WHERE (((tblNodes.NodeID)=" & m_lngNodeID & "));"
set RS=server.CreateObject("adodb.Recordset")
RS.CursorType = 1
RS.LockType = 2
RS.Open SQL, conn
With RS
If not .Fields("SingleSiteChildID") >0 or isnull(.Fields("SingleSiteChildID")) then
If m_lngChildCount>0 then
.Fields("SingleSiteChildID")=0
m_lngSingleSiteChildID=0
Else
.Fields("SingleSiteChildID")=null
m_lngSingleSiteChildID=null
End if
.UPDATE
End if
END WITH
RS.Close
Set RS = Nothing
Set conn = Nothing
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以按照与目前使用其他数据库完全相同的方式使用 Recordset 和 Command 对象。
如果您使用 DSN,您所需要做的就是为 MySQL DB 创建一个系统 DSN,尽管无 DSN 连接是更好的方法。
前往 MySQL 站点安装 ODBC 驱动程序 然后您的连接字符串将类似于这个:
快速 Google 一下,检查一下指定的选项是否适合您,我已从使用 MySQL 的工作经典 ASP 站点中摘录了此内容。
只需切换连接字符串就可以让您非常简单地迁移到新的数据库类型。请检查所有 SQL 命令是否符合 MySQL 标准,并且不要使用 MSSQL 或 Access 特有的单词,例如
TOP
仅适用于 MS,对于 MySQL 使用LIMIT
。You can use Recordset and Command objects in exactly the same way you are use other databases at the moment.
If you use DSNs, all you need to do is create a system DSN to the MySQL DB, although a DSN-less connection is a better way of doing it.
Head to the MySQL site to install the ODBC drivers then your connection string will look something like this:
Do a quick Google to check that the options specified there are correct for you, I have ripped this from a working Classic ASP site that uses MySQL.
Simply switching the connection string should allow you to migrate very simply to a new DB type. Do check that all your SQL commands conform to MySQL standards, and do not use words specific to MSSQL or Access, e.g.
TOP
is MS only, useLIMIT
for MySQL.