Is this so bad when using MySQL queries in PHP?

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-04-06T00:30:09Z Indexed on 2010/04/06 0:33 UTC
Read the original article Hit count: 680

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql