Help, Check connection to database

Hi,

I have an application that will be used through 4G connections on tablets.
I have verified that when we I fill a form and save the changes, if there is no connection to the database, the system is “processing” and the data finally is lost.
How can I check the connection with the database before saving the changes?
And in case there is no connection to the database, shows a message and wait for connection to save the changes.

Thanks for your help.

not tested as I’ve never had this requirement, but maybe it could work:

  1. in your DB create a dumb table with just one field; populate one record with any value in that field (e.g. “1”)
  2. onValidate in SC
    – check if you can retrieve the value “1” form the dumb table\field using sc_lookup();
    – if not, execute sc_error_message(“DB not availabile, try again in a few minutes”);

No Robydago,
Remember that php is executed on server side and I want to check on client side

connection_aborted ( void ) : int

https://www.php.net/manual/en/function.connection-aborted.php

I should have read your post better.
I thought that you had connection problems from the web server to the db server (possible if they are not running on the same machine).

If the check must run on the client you have to use JavaScript.
I guess there’s a way to check if the web server is reachable in JS or Jquery, use Google.
If there is, in SC you could hide the standard insert/update buttons and use your custom JS button that can trigger the standard buttons only when the server is reachable.
​​​​​​

I used this, and I have not changed the code for your purposes but it should set you in the right direction. Your blank php should test the connection. It is javascript.

callPHPMethod(’…/blank_js/index.php?timestamp=’ + timestamp + ‘&bot_run=’ + botrun, function(returnedPHPfunctionValue){
console.log(returnedPHPfunctionValue);
});

The blank_js.php is this where the connection is tested and you then echo the result to pick it up in JavaScript again as returnedPHPfunctionValue

Here is the function (again in javascript)

function callPHPMethod(method, callback)
{
$.ajax({
url: method,
method: ‘GET’,
success: function(data){
if($.isFunction(callback)) callback(data)
},
error: function(){
//do something with error
}
});
}