INSERT IGNORE using Codeigniter

后端 未结 13 929
眼角桃花
眼角桃花 2020-12-08 19:52

I am trying to insert a few rows into the MySQL table using Codeigniter and Active Records.

PHP Code

$data = array(\'......\');  //          


        
13条回答
  •  北海茫月
    2020-12-08 20:40

    For batch uploads you might need something more like:

    foreach ($data as $data_item) {
        $insert_query = $this->db->insert_string('my_table', $data_item);
        $insert_query = str_replace('INSERT INTO', 'INSERT IGNORE INTO', $insert_query);
        $this->db->query($insert_query);
    }
    

    UPDATE: Use dcostalis's version (in the comments below this one), it will scale much better :-)

提交回复
热议问题