Я искал код для добавления «INSERT IGNORE INTO» вместо «INSERT INTO» в запросе пакетной вставки codeigniter, но я не нашел для этого результатов. Да, мы можем сделать наш пользовательский пакетный запрос вставки с помощью входа в PHP. Но если вы хотите сделать это в codeigniter, используйте эту функцию.
Добавьте эту функцию в (codeigniter/system/database/DB_active.rec.php).
/*
*Function For Batch Insert using Ignore Into
*/
public function custom_insert_batch($table = '', $set = NULL)
{
if (! is_null($set))
{
$this->set_insert_batch($set);
}
if (count($this->ar_set) == 0)
{
if ($this->db_debug)
{
//No valid data array. Folds in cases where keys and values did not match up
return $this->display_error('db_must_use_set');
}
return FALSE;
}
if ($table == '')
{
if (! isset($this->ar_from[0]))
{
if ($this->db_debug)
{
return $this->display_error('db_must_set_table');
}
return FALSE;
}
$table = $this->ar_from[0];
}
// Batch this baby
for ($i = 0, $total = count($this->ar_set); $i < $total; $i = $i + 100)
{
$sql = $this->_insert_batch($this->_protect_identifiers($table, TRUE, NULL, FALSE), $this->ar_keys, array_slice($this->ar_set, $i, 100));
$sql = str_replace('INSERT INTO','INSERT IGNORE INTO',$sql);
//echo $sql;
$this->query($sql);
}
$this->_reset_write();
return TRUE;
}
Чтобы использовать эту функцию
$this->db->custom_insert_batch($table_name, $batch_data);
Спасибо!
Возможный дубликат [INSERT IGNORE using Codeigniter] (http://stackoverflow.com/questions/10965792/insert-ignore-using-codeigniter) – Gunaseelan
@ Gunaseelan: означает, что INSERT IGNORE добавит повторяющиеся строки в таблицу? –
не будет добавлять повторяющиеся строки. – Gunaseelan