Is there INSERT IGNORE equivalent for MDB2 batch queries autoPrepare & executeMultiple MDB2_AUTOQUERY_INSERT

226 views Asked by At

I have an index on my MYSQL database table across two fields. I batch the INSERTS using autoPrepare & executeMultiple which PHP MDB2 MYSQL extension offers. If there is a duplicate hit on my index however it throws an error and stops the batch insert. I'm looking for the INSERT IGNORE equivalent, which is a MYSQL command that just ignores the error if a duplicate is attempted.

Batch inserts let you specify the table fields in an array, specify the field types, and then all of the values to be entered in an array. You end up with something like :

$sth = $db->extended->autoPrepare($table_name, $table_fields,MDB2_AUTOQUERY_INSERT, null, $types);
$res = $db->extended->executeMultiple($sth, $table_values);

So no specific query is sent. I need to somehow send an option so it knows not to throw an error on a duplicate, but just to ignore the entry.

1

There are 1 answers

0
jozero On

Gave up on using Batch inserts with MDB2. Instead used an normal insert with ignore :

INSERT IGNORE into TABLENAME (field1, field2) VALUES (1,2), (a,b) ...

The index is on field1 & field2 together. The IGNORE skips the entry if its a duplicate attempt on an indexed value, but unlike the MDB2 batch command the IGNORE option lets the query continue if it hits a repeat entry scenario.