How to disable MySQL's errors?

Problem :

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.

My questions:

  1. Can I turn off those errors?
  2. Is there a better way to prevent inserting duplicates than making an extra query?

Solution :

You could use the IGNORE keyword to have duplicates dropped from your inserts:

INSERT IGNORE INTO yourTable Values (...)

Mysql Tutorials

Mysql Howto..

How to display monthwise report in mysql

How to search a 'near word' in MySQL?

How to get multiple max column value mysql

MySQL Apostrophe- How to escape and return correct results with MATCH/AGAINST

How to create a set of rows from a number in MySQL

MySQL: How do I use delimiters in triggers?

Show the different value from a database field

how to print the count number in mysql?

How to check a Radio button from the value of a table of mySQL

How to create MySQL Table with no Insert allowed

How to fetch all the results from MySQL table?

How to make login with userid or mobile number using php mysql [closed]

How does PDO know last inserted id in MySQL?

MYSQL- How do I create individual tables for forum posts?

how to calculate time difference between two dates? - MySql

How to run a mysql loop from a posted array and extract results to a CSV file

How do I insert a date into mysql as a parameter?

How to get last 12 digits from a string in MySQL?

how to store a date in a mysql database?

How to prevent MYSQL table for any updating independent of session?

how to run mysql from the command line on mac?

How to write golang integration test with MySQL

How to write Nhibernate Query C# .net Mysql

How do I use Doctrine 2.0 ORM models to select database data?

how to use variable in mysql date format

How to set initial value and auto increment in MySQL?

How to sort by name and surname from MySql using php?

MYSQL: How can I get data from a single column for different rows? [closed]

In mysql, how to I query to see if a specific user is in a table? [closed]

How to output MySQL query results in csv format in Windows environment?