CodeIgniter- active record insert if new or update on duplicate

前端 未结 8 731
醉酒成梦
醉酒成梦 2020-12-29 04:46

Is it possible to do an active record query in CodeIgniter that will update an existing record if one already exists or insert if it doesnt, for the given k

8条回答
  •  长发绾君心
    2020-12-29 05:25

    You could do it simpler:

    $sql = $this->db->insert_string(table, $array) . ' ON DUPLICATE KEY UPDATE ' .
    implode(', ', $array);
    $this->db->query($sql);
    

提交回复
热议问题