public function insertUnique(Entity $entity) { // First check $entity is already in DB $sql = <<<SQL \t\t\tSELECT \t\t\t\t`user` \t\t\tFROM \t\t\t\t`*PREFIX*chat_och_users_in_conversation` \t\t\tWHERE \t\t\t\t`user` = ? \t\t\tAND \t\t\t\t`conversation_id` = ? SQL; try { $result = $this->findOneQuery($sql, array($entity->getUser(), $entity->getConversationId())); // The user already joined the conv -> nothing to do } catch (\Exception $exception) { // The user isn't in this conversation -> add it $sql = <<<SQL \t\t\tINSERT \t\t\tINTO `*PREFIX*chat_och_users_in_conversation` \t\t\t( \t\t\t\t`user`, \t\t\t\t`conversation_id`, \t\t\t\t`joined` \t\t\t) VALUES ( \t\t\t\t?, \t\t\t\t?, \t\t\t\t? \t\t\t) SQL; $this->execute($sql, array($entity->getUser(), $entity->getConversationId(), $entity->getJoined())); } }