I have a bunch of insert querys running and some of them fail with a duplciate entry.

I want to see a log where it says "Error: Duplicate key" and that tells me the EXACT INSERT query that fails so I can see what keys are duplicated.



Try INSERT IGNORE in place of INSERT and it will ignore the duplicate key errors.

Member Avatar


mysql_query($sql); //or use mysqli equivalents
if (mysql_errno() == 1062) {
    echo "Duplicate key error: <pre><code>$sql</code></pre>";

I went ahead with REPLACE but thank you

And this isnt a PHP question.