Home > codeigniter

Codeigniter insert if not exist and update if not

Codeigniter insert if not exist and update if not First you need to check whether the user or data is exits or not. after that you can perform the update and insert operation. $this->db->where('user_id',$id); $q = $this->db->get('profile'); if ( $q->num_rows() > 0 ) { $this->db->where('user_id',$id); $this->db->update('profile',$data); } else { $this->db->set('user_id', $id); $this->db->insert('profile',$data); } There is one more way by using mysql query

Read More