Connect to mysql 5.0 database using pure vbscript?

48,324

Solution 1

Install MySQL Connector/ODBC and use a connection string like the following

connectionString = "Driver={MySQL ODBC 5.1 Driver};Server=yourServerAddress;" & _
                   "Database=yourDataBase;User=yourUsername;" & _
                   "Password=yourPassword;"

Solution 2

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"
Share:
48,324
deostroll
Author by

deostroll

You are probably reading this space for the WRONG reasons...statistically speaking. Why? Because the SO community isn't so welcoming... But we can make this work...just hang in there... :) https://codeblog.jonskeet.uk/2018/03/17/stack-overflow-culture/amp/ (At least, read the "Jon’s Stack Overflow Covenant" section) About me Software engineer. Loves JavaScript. Python. Science. Astronomy. IoT. Programming. Movies. Computers. Married. 1 Kid. From Kerala, India. Works in Bangalore. More ways to connect -> https://plus.google.com/+ArunJayapal (linkedin, facebook, twitter, blah, blah)

Updated on September 20, 2020

Comments

  • deostroll
    deostroll over 3 years

    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 this page where I could download the odbc 5.1 connector. Wondering if this is enough to connect to a mysql server 5.0 database...?

  • deostroll
    deostroll over 14 years
    no this does not work...I have installed the 5.1 connector correctly.
  • deostroll
    deostroll over 14 years
    It worked. I'm sorry...my bad. Instead of "Driver" I typed "Provider".
  • Ranjit Kumar
    Ranjit Kumar over 11 years
    will "load data local infile ......... " command works in the same code ?? please help me
  • Tanzeel
    Tanzeel almost 7 years
    variable i and variable connectionString are not defined