Hello.
I'have some difficulties dealing with error handling with postgreSQL and the DB_Sql class from phplib.
Here is a summary: i need to launch a list of sql queries in a transaction and check if the queries were made successfully.
So, if a delete from table is not possible because the data involved is still referenced by a foreign tuple, i want to be able to know the error and ask for a rollback.
Here is how i launch the transaction:
$db=new DB_Sql;
$db->Halt_On_Error="no";
$snt="begin";
$db->query($snt);
...some other queries....
$snt="delete from users where id_user='$iduser'";
$db->query($snt);
if($db->Error)
{
print "Erreur:<br>".$db->Error;
$db->query("rollback");
}
else {$db->query("commit"); }
However, if the last sentence cannot be performed, the application stops with the following error message:
Warning: PostgreSQL query failed: ERROR: referential integrity violation - key in users still referenced from
commerciaux in /usr/local/apache/htdocs/intranet/inc/db_pgsql.inc on line 67
Database error: Invalid SQL: delete from users where id_user='13'
PostgreSQL Error: 1 (ERROR: referential integrity violation - key in users still referenced from commerciaux
)
Session halted.
Why did the $db->Halt_On_Error="no"; sentence did not worked ?
I though it shall made the application continue even in case of error, but
it does not, so the transaction is never commited or rollbacked and
everything does not work anymore.
Any idea will be greatly appreciated.
I'have some difficulties dealing with error handling with postgreSQL and the DB_Sql class from phplib.
Here is a summary: i need to launch a list of sql queries in a transaction and check if the queries were made successfully.
So, if a delete from table is not possible because the data involved is still referenced by a foreign tuple, i want to be able to know the error and ask for a rollback.
Here is how i launch the transaction:
$db=new DB_Sql;
$db->Halt_On_Error="no";
$snt="begin";
$db->query($snt);
...some other queries....
$snt="delete from users where id_user='$iduser'";
$db->query($snt);
if($db->Error)
{
print "Erreur:<br>".$db->Error;
$db->query("rollback");
}
else {$db->query("commit"); }
However, if the last sentence cannot be performed, the application stops with the following error message:
Warning: PostgreSQL query failed: ERROR: referential integrity violation - key in users still referenced from
commerciaux in /usr/local/apache/htdocs/intranet/inc/db_pgsql.inc on line 67
Database error: Invalid SQL: delete from users where id_user='13'
PostgreSQL Error: 1 (ERROR: referential integrity violation - key in users still referenced from commerciaux
)
Session halted.
Why did the $db->Halt_On_Error="no"; sentence did not worked ?
I though it shall made the application continue even in case of error, but
it does not, so the transaction is never commited or rollbacked and
everything does not work anymore.
Any idea will be greatly appreciated.