Try the following:
try { //Initial query processing $execute = $query->execute() if (!$execute) { //catch the exception throw new Exception ("blah") } } catch (Exception $e) { //Exception logic here }
Write your queries like this, and if they encounter an exception in the try section, it will go into the catch section and you will be able to handle it as you like (regardless of whether the ID depends on a specific case).
If there are no exceptions, it will never reach the catch statement, and your request will simply be executed.
When it comes to DUPLICATES -> you need to get around this in SQL. For example, your request could be:
INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);
mlishn
source share