MySQL在重复键上插入更新多个值

问题描述:

Im当前将大量(100k +)行插入表中,如下所示:

Im currently inserting a large amount (100k+) of rows into a table as follows:

//START of a loop

$updatedData[] =  '(
                      "'.$field_1.'",
                      "'.$field_2.'",
                      "'.$field_3.'"
                   )';
//END of loop

$updatedData = implode(',', $updatedData);

$query = "INSERT INTO table (field_1,field_2,field_3) VALUES $updatedData";

这一切都很好,但是现在我正在寻找一种方法来更新行,而不是如果$ field_1和$ field_3是重复的,则不插入新行.

This is all working perfectly, but now I'm looking for a way to update a row instead of insert a new one if $field_1 and $field_3 are duplicates.

只需对您的$ updatedData进行计数.

Just take counter of your $updatedData.

并以循环方式运行,即可按需运行.

And run that in loop this will run as you want.

祝一切顺利.

汉字