is there a more clever way to see if revOpenDatabases() contains a valid value?

Ken Ray kray at sonsothunder.com
Thu Apr 19 23:53:04 EDT 2007


On Thu, 19 Apr 2007 17:59:40 -0700, Josh Mellicker wrote:

> If I revCloseDatabases() or resetAll and establish a new connection 
> before making any database command all is fine, but I am thinking 
> this is an inefficient approach... or is it?
> 
> 
> So I am wondering if there is any clever way, perhaps through 
> checking sockets or other network wizardry, to verify a valid MySQL 
> database connection before actually executing a database command?

Well, the way we do it is to bundle mySQLAdmin with our app. Then, 
whenever we are about to execute a DB command, we use the "ping" 
command-line call to mySQLAdmin which should return "mysqld is alive". 
If it doesn't, we respond with a Server Disconnected error, or 
automatically go into a loop until the "ping" shows it's alive or a 
certain timeout has expired. Here's the basic call to mysqladmin:

  <pathToMySQLAdmin> --host=<IPAddress> --port=<port> --user=<userName> 
--password=<password> ping

as in (for Mac OS X):

  put "/Users/kenray/Applications/MyApp/support/mysqladmin" into tAdmin
  put tAdmin && "--host=255.255.255.255 --port=3631 --user=ken 
--password=password ping" into tCmd
  put shell(tCmd) into tResult
  return (tResult <> "mysqld is alive")

HTH,

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/



More information about the use-livecode mailing list