Hallo maxi,
Hallo Vincenzo,
I believe, that your problem is not the missing error out of sc_select within Ajax, but that the result will not be displayed.
Therefore lets expand the original function asdw_exec() a little bit into:
function asdw_exec_sql($befehl)
{ // Improved sc_select with error handling
sc_select(asdw_my_data,$befehl);
if ({asdw_my_data} === false)
{
asdw_error({asdw_my_data_erro}. " aus SQL: " . $befehl);
}
else
{
return({asdw_my_data});
}
}
You will notice, that -in the case of an error- not die() is used, but another function named asdw_error().
The new function:
function asdw_error($t_message)
{
// Error-handler
if ($this->NM_ajax_flag == 1)
{
$t_error_msg = '<font color="red"><br>FATAL ERROR : ' . str_replace('<br>','',$t_message)
. '<br><br>' . date("Y-m-d H:i:s")
. '<br>Project: ' . $this->Ini->nm_grupo
. '<br>Application: ' . $this->Ini->nm_cod_apl
. '</font>';
sc_alert($t_error_msg);
sc_error_message('asdw_error');
sc_error_exit();
}
else
{
echo '<font color="red"><br>FATAL ERROR : ' . str_replace('<br>','',$t_message)
. '<br><br>' . date("Y-m-d H:i:s")
. '<br>Project: ' . $this->Ini->nm_grupo
. '<br>Application: ' . $this->Ini->nm_cod_apl
. '</font>';
die();
}
}
In this function there is an if
to check, if currently AJAX is in use or not.
If Ajax is used, the function uses sc_alert()...
if not, it uses echo
and die()
.
You can also see that the current project and the application where the error happened is shown.
Nice detail if you want to get a more detailed feedback from your users
Sample:
If your using the following code within a form in a button of type PHP or a button of type AJAX, you will get slightly different messages:
// Wrong SQL code to get an error !!
$my_sql = "UPDATE ge_test SET text_1=‘Hallo World.’ WHERE id=abc ";
$result = asdw_exec_sql($my_sql);
Using the PHP button:
Using the Ajax button:
Note:
There are plenty of these asdw_… functions building libraries for different use cases.
We use them when teaching Scriptcase and developing projects for our Scriptcase.coaching customers.
I hope this will help a little bit.
Sincerely
Gunter Eibl