Friday, February 3, 2017

VBScript MySql connection

You have to install mysql odbc connector first.

Dim Connection, ConnectString

ConnectString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;PORT=3306;Database=database;User=root;Password="

Set Connection = CreateObject("ADODB.Connection")

Connection.Open ConnectString

Sql = "SELECT id,created_at FROM table ORDER BY id DESC LIMIT 0, 10"
Set Result = Connection.Execute(Sql)

Do Until Result.EOF
    Wscript.Echo "Id=" + CStr(Result(0)) + ",Create_Date=" & FormatDateTime(Result(1), 1)
    Result.MoveNext
Loop

Connection.Close

2 comments:

  1. Can you let me know what is the connection string for ODBC Driver 8.0.15

    ConnectString = "Driver={MySQL ODBC 3.51 Driver};Server=localhost;PORT=3306;Database=database;User=root;Password="

    ReplyDelete
  2. Look at the drivers in your computers ODBC panel and use that name as is.

    ReplyDelete