使用纯 vbscript 连接到 mysql 5.0 数据库?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1366516/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connect to mysql 5.0 database using pure vbscript?
提问by deostroll
I've tried the below script but I am getting an error:
我已经尝试了以下脚本,但出现错误:
dim cn, rs
set cn = CreateObject("ADODB.Connection")
set rs = CreateObject("ADODB.Recordset")
cn.connectionstring = "Provider=MysqlProv; Data Source=Adonis; User Id=mysqluser; Password = mysqlpass;"
cn.open
rs.open "select * from Countries", cn, 3
rs.MoveFirst
while not rs.eof
wscript.echo rs(0)
rs.next
wend
cn.close
wscript.echo "End of program"
Its giving the following error:
它给出了以下错误:
C:\mysql.vbs(6, 1) ADODB.Connection: Provider cannot be found. It may not be pro
perly installed.
When I googled for an odbc connector I came up to thispage where I could download the odbc 5.1 connector. Wondering if this is enough to connect to a mysql server 5.0 database...?
当我在谷歌上搜索 odbc 连接器时,我来到了这个页面,在那里我可以下载 odbc 5.1 连接器。想知道这是否足以连接到 mysql server 5.0 数据库...?
回答by Anton Hansson
Install MySQL Connector/ODBCand use a connection stringlike the following
安装MySQL连接/ ODBC,并使用一个连接字符串类似以下
connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=yourServerAddress;" & _
"Database=yourDataBase;User=yourUsername;" & _
"Password=yourPassword;"
回答by Venu Gopi
I made small changes to the above script and is working fine:
我对上面的脚本做了一些小的改动并且工作正常:
dim cn, rs
i = 0
set cn = CreateObject("ADODB.Connection")
set rs = CreateObject("ADODB.Recordset")
connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;" & _
"Data Source=dsn_hb; Database=TP; User=root; Password=***;"
cn.Open connectionString
rs.open "select * from test.Login", cn, 3
rs.MoveFirst
'msgbox rs(0)'
while not rs.eof
msgbox rs.Fields(0)
rs.MoveNext
wend
cn.close
MsgBox "End of program"