Is there a way to accomplish this?
INSERT IGNORE INTO some_table (one,two,three) VALUES(1,2,3)
ON DUPLICATE KEY (INSERT INTO audit_table VALUES(NOW(),'Duplicate key ignored')
I really don’t want to use PHP for this 🙁
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to consider using a stored procedure, you can use a
DECLARE CONTINUE HANDLER. Here’s an example:Let’s add some data, trying to insert a duplicate key:
Result:
If auditing is important on a database level, you may want to grant
EXECUTEpermissions only so that your database users can only call stored procedures.