I try to upgrade my PDOException handling code to retry on error when it makes sense. For this I need to distinguish between syntax error and deadlock, connection error, etc. I tried to find the PDOException error codes to be able to do so, but I had no luck. Did any of you manage to distinguish between these errors?
My current scenario that I have a transaction in a cron which inserts or updates a table and another transaction that deletes from the same table when there is user interaction. I got a deadlock a few times a week. My current code just logs the PDOException and keeps doing its work, but it is pointless when the entire transaction is gone. I want to retry in these cases and only in the case of syntax or out of range parameter error I want to ignore it and keep working and commit the transaction. How do you check the type of the PDOException in your code?