[PHP] Database Insert/Update/Delete
- Date: Thu, 08 Oct 2015 21:45:56 +0100
- From: Ashley Sheridan <ash@xxxxxxxxxxxxxxxxxxxx>
- Subject: [PHP] Database Insert/Update/Delete
This is a bit of an odd one, and while it's largely an SQL problem, it
will have PHP logic because SQL just doesn't have quite the syntax.
I'm sure this is a standard problem that has a standard solution, but as
of yet, I've not come across said solution.
I need to update a series of data in a DB. Some of it may exist already,
and some may need to be removed.
Now the typical for updating (but not removing) data and adding new is
INSERT ... ON DUPLICATE KEY UPDATE ...
syntax, but what about those bits which might need removing?
What's the typical solution that any of you use? I normally just empty
all rows of data sharing the common id for the set of data and then
insert new rows, but that seems wasteful to me, and less clean than it
ought to be.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php