How to disable MySQL's errors?
I have a table in my database with a string for a primary_key, which I set. I need to check frequently if around 1000 "items" exist in that table before adding them, because there must not be any duplicates. The result is 2 queries per Item, or 2000 total, which is 1-2 seconds of extra loading time.
If I try to insert the new row anyway, without checking for duplicates it doesn't get inserted and that's great, but mysql returns an error, which crashes my service.
- Can I turn off those errors?
- Is there a better way to prevent inserting duplicates than making an extra query?
You could use the
IGNORE keyword to have duplicates dropped from your inserts:
INSERT IGNORE INTO yourTable Values (...)
- A Linux, Apache, MySQL, PHP (LAMP) stack is a combination of open source software that is typically installed together to enable a server to host dynamic […]
- MySQL is an the most popular open-source database management system, in most of hosting company its has been bundle by LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. Another alternative […]
- MySQL is the world’s most popular open-source database. Despite its powerful features, MySQL is simple to set up and easy to use. Below are some instructions […]