I have a cool example how to detect duplicate records without having to perform a SELECT on the database:

try{
$pdo->query(“INSERT INTO `table`(`name`,`value`)`VALUES(‘name’,’value’)”);
} catch (PDOException $e) {
if($e->errorInfo[0] == ‘23000’ && $e->errorInfo[1] == ‘1062’){
throw new CustomException(“Bla bla already exists”);
} else {
throw $e;
}
}

I use it in all my API’s and it helps a lot.