Is this so bad when using MySQL queries in PHP?
- by alex
I need to update a lot of rows, per a user request. It is a site with products.
I could...
Delete all old rows for that product, then loop through string building a new INSERT query. This however will lose all data if the INSERT fails.
Perform an UPDATE through each loop. This loop currently iterates over 8 items, but in the future it may get up to 15. This many UPDATEs doesn't sound like too good an idea.
Change DB Schema, and add an auto_increment Id to the rows. Then first do a SELECT, get all old rows ids in a variable, perform one INSERT, and then a DELETE WHERE IN SET.
What is the usual practice here?
Thanks