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
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 theINSERT
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 manyUPDATE
s doesn't sound like too good an idea. - Change DB Schema, and add an
auto_increment
Id to the rows. Then first do aSELECT
, get all old rows ids in a variable, perform oneINSERT
, and then aDELETE WHERE IN SET
.
What is the usual practice here?
Thanks
© Stack Overflow or respective owner