How would I use ON DUPLICATE KEY UPDATE in my CodeIgniter model?

前端 未结 8 1524
暖寄归人
暖寄归人 2020-11-30 07:27

I have a CodeIgniter/PHP Model and I want to insert some data into the database.

However, I have this set in my \'raw\' SQL query:

ON DUPLICATE KEY U         


        
8条回答
  •  醉梦人生
    2020-11-30 08:05

    The link to the forum thread above is broken. I don't know of a better way than just using db->query for the call, if someone has a better solution, please post that.

    $result = $this->CI->db->query(
        "INSERT INTO tablename (id, name, duplicate) VALUES (1, 'Joe', 1) ".
        "ON DUPLICATE KEY UPDATE duplicate=duplicate+1");
    

    I hope this helps someone looking for a solution to this.

提交回复
热议问题