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.
Thanks
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.
Thanks
Hello,
Try INSERT IGNORE in place of INSERT and it will ignore the duplicate key errors.
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.
No prob. I assumed that you wanted to log these specific fails in a custom log file. So where 'echo', you could just append the SQL to a text file instead.
With REPLACE - be aware of a few things...
http://stackoverflow.com/questions/548541/insert-ignore-vs-insert-on-duplicate-key-update (selected answer).
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.