WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

MySql Example

 Keywords: MySql ADO ADODB Connection Recordset MySQL ODBC 5.1 Driver  

SERVER = 'xxxxxxxxx'
uid    = 'xxxxx'
pwd    = 'xxxxxxxxx'
db     = 'xxxxxxxxxxx'

adOpenStatic           = 3
adLockReadOnly         = 1
adCmdText              = 1

myConn = ObjectCreate('ADODB.Connection')
myRS   = ObjectCreate('ADODB.Recordset')
myRS.CursorLocation = 3
myConn.ConnectionString = "Driver={MySQL ODBC 5.1 Driver}; Server=%server%; UID=%uid%; PWD=%pwd%; Option=71303168; Database=%db%"
myConn.CommandTimeout = 360
myConn.Open
If myConn.Errors.Count > 0
ForEach errLoop In myConn.Errors
     strError = "Error #" : errLoop.Number : @CRLF :"   " : errLoop.Description : @CRLF :"   (Source: " : errLoop.Source : ")" : @CRLF :"   (SQL State: " : errLoop.SQLState : ")" : @CRLF :"   (NativeError: " : errLoop.NativeError : ")" : @CRLF
     If errLoop.HelpFile == ""
        strError = strError :"   No Help file available"
     Else
        strError = strError :"   (HelpFile: " : errLoop.HelpFile : ")" : @CRLF :"   (HelpContext: " : errLoop.HelpContext : ")"
     EndIf
     Pause('error', strError)
 Next
 Exit
EndIf


SQLText = "Select * from YOUR_TABLE"
myRS.Open (SQLText, myConn, adOpenStatic, adLockReadOnly, adCmdText)

;############################
If myRS.EOF == @FALSE Then
 vtxt1  =  myRS.GetString() ;@TAB Delimiter columns with @CR delimited rows.
 FilePut("file_vtxt.txt",vtxt1)
EndIf

;############################
myRS.MoveFirst
If myRS.EOF == @FALSE Then
 varr   =  myRS.GetRows(-1) ;An Array of all records
 ArrayFilePutCSV("file_varr.txt",varr)
EndIf

;############################
myRS.MoveFirst
; While myRS.EOF == @FALSE
;   vname =  myRS.fields("vname").value   ; Will retrieve column values row by row
; EndWhile

;############################


myRS.Close


myConn.Close
myRS = 0
myConn = 0

Article ID:   W18066
Filename:   MySql Example.txt
File Created: 2012:04:17:15:18:06
Last Updated: 2012:04:17:15:18:06