Skip to content

Instantly share code, notes, and snippets.

@musahi0128
Last active May 7, 2022 11:58
Show Gist options
  • Save musahi0128/16364da973e45f5272b60fad916b290b to your computer and use it in GitHub Desktop.
Save musahi0128/16364da973e45f5272b60fad916b290b to your computer and use it in GitHub Desktop.
Sample codes to get query result and execute query against MySQL/MariaDB database using AutoIT and ODBC without creating ODBC data source
Global $sDBDriver = "{MariaDB ODBC 3.1 Driver}"
GLobal $sDBServer = "localhost"
Global $sDBUID = "root"
Global $sDBPWD = "pwd"
Global $sDBName = "dbname"
Global $sDBPort = "3306"
Global $sConnectionString = 'Driver=' & $sDBDriver & ';Server=' & $sDBServer & ';UID=' & $sDBUID & ';PWD=' & $sDBPWD & ';DB=' & $sDBName & ';Port=' & $sDBPort
Func _GetQueryResult($sQuery = "")
; If you don't want to make custom error handler, make sure the query always return a row
$DB = ObjCreate("ADODB.Connection")
$DB.Open($sConnectionString)
$Result = $DB.Execute($sQuery).GetRows()
$DB.Close
Return $Result
EndFunc ;==>_GetQueryResult
Func _QueryExecute($sQuery = "")
$DB = ObjCreate("ADODB.Connection")
$DB.Open($sConnectionString)
$Result = $DB.Execute($sQuery)
$DB.Close
EndFunc ;==>_QueryExecute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment