mySQL Examole and first steps in LiveCode

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
dx111ge
Posts: 2
Joined: Sun Jul 27, 2014 10:13 am

mySQL Examole and first steps in LiveCode

Post by dx111ge » Sun Jul 27, 2014 10:22 am

Good Morning,

please be aware i´m just started with my first test in Livecode and it seems to be very impressive. With the help of the examples i could connect to my own mysql Server from Mac and Windows. Making those working, i did try to change the code and add a disconnect. Basically if have two Buttons now : Connect and disconnect. See the code below. I thought the global gConnectionID would be available in the disconnect script, but it seems to be wrong. Maybe someone can shed some light on my dumb head ?
Thanks in advance

Code: Select all

  -- Connect Button
       -- use a global variable to hold the connection ID so other scripts can use it
       global gConnectionID
       
       -- set up the connection parameters - edit these to suit your database
       put "DBServer" into tDatabaseAddress
       put "test" into tDatabaseName
       put "xxxxxxx" into tDatabaseUser
       put "xxxxx" into tDatabasePassword
       
       -- connect to the database
        if gConnectionID is empty then put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
       
       -- check if it worked and display an error message if it didn't
       -- & set the connection ID global
       if tResult is a number and gConnectionID is empty then
              put tResult into gConnectionID
              answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID as sheet
    else if gConnectionID is not empty then
      answer info "Connected to the database." & cr & "Connection ID = " & gConnectionID as sheet
      else 
              put empty into gConnectionID
              answer error "Unable to connect to the database:" & cr & tResult 
       end if
   set the enabled of Button Disconnect to true
end mouseUp

Code: Select all

 -- Disconnect Button
on MouseUp
   answer info " ich schliesse " & gConnectionID as sheet
   revCloseDatabase gConnectionID
   
end MouseUp

Peter Wood
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 92
Joined: Mon Jul 06, 2009 4:53 am

Re: mySQL Examole and first steps in LiveCode

Post by Peter Wood » Sun Jul 27, 2014 10:58 am

As far as I remember, you need to declare the global variable in each script that you wish to use it. Try adding

Code: Select all

global gConnectionID
at the top of your Disconnect Button script

dx111ge
Posts: 2
Joined: Sun Jul 27, 2014 10:13 am

Re: mySQL Examole and first steps in LiveCode

Post by dx111ge » Sun Jul 27, 2014 11:02 am

Thank you very much , it works now !

Post Reply