I have a mysql db with two tables. The first table is called 'uniqueReferences' and the second one 'duplicatedReferences'. The two tables have two fields only: an id field (auto-incremented) and a field called Reference. What I would like is as follows. When trying to insert a ref in the 'uniqueReferences' table, if the reference already exists, do not insert it in that table but in the table 'duplicatedReferences'.
So what I tried but did not work is the following.
1-> set the field reference of my 'uniqueReferences' table as 'unique'.
2-> Make the following
try{
$req = $prepared_insertQry_toUniqueRefTable -> execute(array(something));
if($req == 0){
$prepared_insertQry_toDuplicateRefTable->execute(array(something));
}
}
catch(PDOException $e){echo $e->getMessage();}
This is unfortunately not working. I have the following error SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry. Hope someone can help. Cheers. Marc
$prepared_insertQry_toDuplicateRefTable ...in thecatchblock (after making sure the exception is the 'duplicate entry' error)?