mysql - Which is better option to avoid duplicate insertion: delete and insert or check and insert? -


just got 1 doubt while performing insert operation. want keep records unique. while inserting record executing delete() function delete same record if exists , using insert() function. thought if check record exists , insert if record not found. can avoid delete() operation. better option?

this code.

public function insertpostlike($postid = null, $userid = null) {          //this avoid duplicate entry same user.         $this->_db->delete($this->_name, array(                 'post_id = ?' => $postid,                 'user_id = ?' => $userid));          $result = '';          $arrdata = array(             'post_id'     => $postid,             'user_id'     => $userid,             'liked_date'  => zend_date::now()->tostring('yyyy:mm:dd hh:mm:ss')         );          if (!is_null($postid)) {             $result = $this->insert($arrdata);         }          return $result;  } 

i using zend framework.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -