Reputation: 26567
In my database there are 3 tables:
Posts:
-id
-title
-body
-date
Tags:
-id
-title
Posts_Tags:
-id
-post_id
-tag_id
When an user insert a post, my php code does 2 queries:
Is this the correct approach ?
Is there a way to simplify or to do 1 single query ?
Upvotes: 0
Views: 85
Reputation: 29912
Is correct approach provided you do it into a transaction (atomic operation); that is, if you insert a post and there's an error into tags insertion (or in tag association insertion), also post will not be inserted
After xRobot comment, I'd updated my answer with this
Upvotes: 2