3
I use the class PDO
for communication with the banco de dados
and I don’t know a good way to capture this exceção
.
I looked for a class that extends PDOException
but I didn’t find.
I can do a query before deleting, it solves, but wanted to treat when the exception is cast, or this is not the best way?
Every "Integrity Constraint Violation" exception comes with an error message that starts with
SQLSTATE[23000]
. Have you tried treating your exception based on this?– Rodrigo Rigotti
Exactly that @Rodrigorigotti, Thanks, with that I found out that the object of the Pdoexception class has a method
getCode()
return the exact number, thanks @Rodrigorigotti– Skywalker
example:
}catch(PDOException $e){ echo $e->getCode();}
– Skywalker