Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7900561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:00:14+00:00 2026-06-03T09:00:14+00:00

I am using autohotkey to make mysql calls. The mysql interface was deciphered by

  • 0

I am using autohotkey to make mysql calls. The mysql interface was deciphered by referencing a visual basic api to mysql.

I am using the mysql connect calls referenced in this post: http://www.autohotkey.com/forum/viewtopic.php?t=12482

I would like to add a dllcall to replicate this perl call to mysql_options…

mysql_options(mysql, MYSQL_OPT_RECONNECT, &true);

It is my understanding that this call would enable my program to gracefully reconnect to mysql after the standard 8 hour mysql timeout. I want my application to remain up indefinitely.

Here is my code. A reference on googles source code libary suggests that the reconnect constant is 20. Everything works except the mysql_opt_reconnect call.

Can anyone help me determine the proper call to libmysql.dll to get my app to automatically reconnect after mysql timeout has occurred?

;============================================================
; mysql.ahk
;
;   Provides a set of functions to connect and query a mysql database
;============================================================

FileInstall, libmysql.dll, %A_AppData%\libmysql.dll, 1

;============================================================
; Connect to mysql database and return db handle
;
; host = DTWRO-WS0061   
; user = alan
; password = *******
; database = rush
;============================================================

dbConnect(host,user,password,database){   

   if (A_IsCompiled) {
      ExternDir := A_AppData
   } else {
      ExternDir := A_WorkingDir
   }

   hModule := DllCall("LoadLibrary", "Str", ExternDir "\libmySQL.dll")

   If (hModule = 0)
   {
      MsgBox 16, MySQL Error 233, Can't load libmySQL.dll from directory %ExternDir%
      ExitApp
   }

   db := DllCall("libmySQL.dll\mysql_init", "UInt", 0)

   If (db = 0)
   {
      MsgBox 16, MySQL Error 445, Not enough memory to connect to MySQL
      ExitApp
   }

    ; figure out how to turn on reconnect call!
    ; mysql_options(mysql, MYSQL_OPT_RECONNECT, &true);
    value := DllCall("libmySQL.dll\mysql_options"
             , "UInt", db
             , "UInt", 20    ; is this the correct constant which represents MYSQL_OPT_RECONNECT?... see below
             , "UInt", 1)   ; true

   connection := DllCall("libmySQL.dll\mysql_real_connect"
         , "UInt", db
         , "Str", host       ; host name
         , "Str", user       ; user name
         , "Str", password   ; password
         , "Str", database   ; database name
         , "UInt", 3306   ; port
         , "UInt", 0   ; unix_socket
         , "UInt", 0)   ; client_flag

   If (connection = 0)
   {
      HandleMySQLError(db, "Cannot connect to database")
      Return
   }

   serverVersion := DllCall("libmySQL.dll\mysql_get_server_info", "UInt", db, "Str")



   ;MsgBox % "Ping database: " . DllCall("libmySQL.dll\mysql_ping", "UInt", db) . "`nServer version: " . serverVersion

   return db

}

;============================================================
; mysql error handling
;============================================================

HandleMySQLError(db, message, query="") {        ; the equal sign means optional
   errorCode := DllCall("libmySQL.dll\mysql_errno", "UInt", db)
   errorStr := DllCall("libmySQL.dll\mysql_error", "UInt", db, "Str")
   MsgBox 16, MySQL Error: %message%, Error %errorCode%: %errorStr%`n`n%query%
   Return
}

;============================================================
; mysql get address
;============================================================

GetUIntAtAddress(_addr, _offset)
{
   local addr

   addr := _addr + _offset * 4

   Return *addr + (*(addr + 1) << 8) +  (*(addr + 2) << 16) + (*(addr + 3) << 24)
}

;============================================================
; process query
;============================================================

dbQuery(_db, _query)
{
    local resultString, result, requestResult, fieldCount
    local row, lengths, length, fieldPointer, field

    query4error := RegExReplace(_query , "\t", "   ")    ; convert tabs to spaces so error message formatting is legible
    result := DllCall("libmySQL.dll\mysql_query", "UInt", _db , "Str", _query)

    If (result != 0) {
        errorMsg = %_query%
        HandleMySQLError(_db, "dbQuery Fail", query4error)
        Return
    }

    requestResult := DllCall("libmySQL.dll\mysql_store_result", "UInt", _db)

    if (requestResult = 0) {    ; call must have been an insert or delete ... a select would return results to pass back
        return
    }

    fieldCount := DllCall("libmySQL.dll\mysql_num_fields", "UInt", requestResult)

    Loop
    {
        row := DllCall("libmySQL.dll\mysql_fetch_row", "UInt", requestResult)
        If (row = 0 || row == "")
            Break

        ; Get a pointer on a table of lengths (unsigned long)
        lengths := DllCall("libmySQL.dll\mysql_fetch_lengths" , "UInt", requestResult)

        Loop %fieldCount%
        {
            length := GetUIntAtAddress(lengths, A_Index - 1)
            fieldPointer := GetUIntAtAddress(row, A_Index - 1)
            VarSetCapacity(field, length)
            DllCall("lstrcpy", "Str", field, "UInt", fieldPointer)
            resultString := resultString . field
            If (A_Index < fieldCount)
                resultString := resultString . "|"     ; seperator for fields
        }

        resultString := resultString . "`n"          ; seperator for records 

    }

    ; remove last newline from resultString
    resultString := RegExReplace(resultString , "`n$", "")    

    Return resultString
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:00:15+00:00Added an answer on June 3, 2026 at 9:00 am

    Even better… I used an oop class to retain the mysql connection parameters, so that when the mysql connection timed out and a new mysql call is made, it can automatically reconnect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a program like AutoHotKey, but with a graphical interface. I'm
Using AutoHotkey, How can I bind a hotkey to stretch/maximize/span a window across multiple
I am currently developing a very simple script in AutoHotKey, but it involves using
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
Using Flex 3, I would like to take an image snapshot such as this:
Using PHP, I can convert MySQL data or static table data to csv, Excel,
Is it possible to select text under cursor using Autohotkey specifically, using a mouse
I am trying to map the following key combinations on my keyboard using AutoHotkey
Using Xcode4.2.1, with a basic PhoneGap template based app. (I say template, but I
Ok, so I've got this AutoHotkey snippet: ; Google text from any app ;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.