php - Updating a many-to-many connector table all at once -


I have two tables:

  article categories   

There are many tables that connect them.

  Create Table Cat 2art (article Iid, category_id INT);   

For a specific article, I have a 'new list' of the Category ID, and we need to update the CatBart table with them.

Some categories were removed, some were added and some were where they were. What is the most effective way to update this table?

I can remove all records with the specified article_id indisputably and can add them again. However, if I record a date in the same table that relates to a category, that information will now be destroyed.

I'm looking for a great pattern that easily solves it issue. This question is especially for PHP and MySQL, but the answers to other languages ​​are also fine, they also apply to PHP + MySQL.

supports other system MERGE statement that actually what you do Want to do

However, in MySQL , you have at least two questions (this can not be deleted / inserted / updated for a single statement):

 cat2art where Art_id = $ art_id and not cat_id ($ new_cat_1, $ new_cat_2, one ????); Cat2art VALUES ($ art_id, $ new_cat_1), ($ art_id, $ new_cat_2) in INSERT, a ?? | |    

Comments