An INSERT into inserts multiple identical records when you insert a record in multiple batches

Source: Internet
Author: User
When you insert a record in multiple batches, a single insert into inserts multiple identical records, and what is the case.
How it should be resolved


Reply to discussion (solution)

Please post the code!!!
When batch is added, do you want to loop it once and add it once, please check the code.

for ($i =0; $i < $s; $i + +) {
$iaps = $IAP [$i];
$daqs = $daq [$i];
$row =mysql_query ("SELECT count (*) from ' DLs ' where ' IAP ' = ' $iaps '"); Check for duplicate data
$row =mysql_fetch_row ($row);
if ($row [0]) {continue;}


mysql_query ("INSERT INTO ' DLS ' (' IAP ', ' Daq ', ' kt ') value (' $iaps ', ' $daqs ', ' kt ')");

}

There is a problem with the loop.
1, the best way to solve the cycle.
2, a field creates a unique index to avoid repeated insertions.
2, avoid repeated insertions with the insert into from dual where NOT EXISTS statement

INSERT into [table name] SELECT ' [value1] ', ' [value2] ' from DUAL
WHERE not EXISTS (
SELECT [Column1] from [same table name]
WHERE [column1]= ' [value1] '
and [column2]= ' [value2] ' LIMIT 1
)

It is best to do things with transactions and ensure consistency.

$row =mysql_fetch_row ($row);
Var_dump ($row); Print results look.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.