A user may enter keywords into a text field and separate the keys using comma.
So the input may be bananas, apple, orange, pineapple
.
In my database, I have a table called keyword
, and it has only one column keyword
which also is the primary key.
I add the keywords to the database, by $myArray = expload(',', $keywords)
.
Then I loop through the array and do a `INSERT INTO myTable'.
Now, if the keyword already exists, I will get an error message.
I can overcome the error message by using the INSERT IGNORE INTO
statement. If the record is a duplicate, the IGNORE keyword tells MySQL to discard it silently without generating an error.
My question is: Is this a good way of doing it? Or should I first check to see if the keyword exists?
I'm kind of thinking two queries vs one. And will this affect server load?