Catch the sql error

I can’t catch the error in the queries I tried with :
sc_exec_sql(“SQL Command”, “Connection”)
also with as suggested in another post but nothing:
sc_select(dataset, “SQL Command”, “Connection”)

do you know how to do it?

Try this macros:

And besides you can use the sc_select to do what you need, instead of the sc_exec_sql macro.

hi,

is only per MSSQL server i use Mysql

i try but not work, any idea?

Hi @marcosc. How did you try it?

sc_lookup(my_data, $MyFileData);

if ({my_data} === false)
{
$MyFileData2=addslashes($MyFileData);
sc_exec_sql(“INSERT INTO ws_error_log SET dati=’$MyFileData2’,error=”.{my_data_error});
//echo “Access error. Message=”. {my_data_error} ;

}
elseif (empty({my_data}))
{
echo “Select command didn’t return data”;
}
else
{
// echo “OK”;
}

Where are you using the sc_select macro? Besides your code is wrong. What I said was about this:

sc_select(meus_dados, "select clienteid, nomecliente, limitecred from clientes");
if ( {meus_dados} === false ) {

  echo "Erro de acesso. Mensagem = " . {meus_dados_erro};

} else {

/// Do what you need
}

The return {meus_dados_erro} gives you the error message came from the database.

sc_select(my_data, $MyFileData);

if ({my_data} === false)
{

$MyFileData2=$MyFileData;
sc_exec_sql("INSERT INTO ws_error_log SET dati='$MyFileData2',error=".{my_data_error});	
//echo "Access error. Message=". {my_data_error} ;
}
else		
{
// INSERT OK
}

ERROR NOT Catch:

<TABLE class="scErrorTable" cellspacing="0" cellpadding="0" align="center">

    <TR>

        <TD class="scErrorTitle" align="left">Errore</TD>

    </TR>

    <TR>

        <TD class="scErrorMessage" align="center">Errore durante l&#039;accesso alla banca dati:<BR>You have an error in your SQL syntax&#059; check the manual that corresponds to your MariaDB server version for the right syntax to use near &#039;63&#039;, parziale=13,100, tempo=0,000, stato=&#039;1&#039;, rotazione=3, ordine=21, turno=0...&#039; at line 1

        </TD>

    </TR>

</TABLE>

Here is your error… so you have to get the error in order to save in yout log table.

hi,
is an API so it shouldn’t return that error but I have to be able to not show it but just insert it into the db, I don’t understand how to do it, the error you see is always written

Can you show the query you have put in your $MyFileData variable?

it’s a simple insert query

Ok, so I really don’t know where the problem is… maybe another person can help you.

@marcosc - I think you just have messed up quotes on your sc_select_sql line, plus the global var that catches the error has no “r” on the end; it should be “erro”, not “error” - try this:

sc_select(my_data, $MyFileData);

$MyFileData2=$MyFileData;

if ( {my_data} === false ) {
    sc_exec_sql( "INSERT INTO ws_error_log SET dati='". $MyFileData2 ."', error='". {my_data_erro} ."'" );	
} else {
    // Whatever else if no error
}