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