work environment: php + mysql
I want to add an entity from DAO layer to database with the following use case:
- Create row in database if it doesn't exist, otherwise, update the record in database.
This needs to be done on a big scale, around 100 million users.
A) In DAO; fetch from database to see if the entity exists. If not, create it in database. If it exists, update the record accordingly.
B) Approach A can be delegated to a procedure in database ? Instead of going back and forth between DAO and DB (which I think is expensive), can we just call a procedure in mysql and let it do the work ?
Also, is there a better way to deal with this situation ?
Scenario:
DB tables
User:
- uid
- name
Post
- pid
- details
- url
UserPosts
- uid
- pid
A user can make many posts. At DAO, I have a user with a list object. I need to add/update the user to database.