1
votes

Using below query to insert update records:

INSERT INTO table (col_a,col_b,col_c,col_d) VALUES (val_a,val_b,val_c,val_d) ON DUPLICATE KEY UPDATE col_d = VALUES(col_d)  

mySQL reports:

1 row affected per insert, 2 rows affected per update, 0 rows affected per duplicate

Followed link : Getting number of rows inserted for ON DUPLICATE KEY UPDATE multiple insert?

but didn't get correct numbers for inserted and updates records.

Is there any way of returning the correct number of inserts, updates and rows skipped (duplicates)?

1
which version of MySQL server you are using? Check this one: bugs.mysql.com/bug.php?id=43311mitkosoft
mysql version is 5.5.28priya gupta

1 Answers

-1
votes

Thanks overflowers, i worked out on a way.. thanks mitksoft for help, used answer given by a user user3556345 on another post - MySQL on duplicate key update + affected row count

using mysql_info() getting actual records, duplicates and skipped rows and warnings if any

Code below:

list($rec, $dupes, $warns) = sscanf(mysql_info($link), "Records: %d Duplicates: %d Warnings: %d"); // courtesy of user at big lake dot com - php.net
$inserts = $total_rows_affected - ($dupes * 2);
$updates = ($total_rows_affected - $inserts)/2;
$skipped = $rec - ($inserts + $updates);
$total = $rec;