Reputation: 19607
I need to synchronize records, say a list of clients, between a local and distant database. The database on both sides has the same structure. I've thought of using some kind of marker (date field, hash/checksum on field values...) but what would you advise ?
Edit: Distant database is on web hosting so PHP will be needed for transferring data.
Upvotes: 2
Views: 532
Reputation: 21856
If you want to sync two databases by code, you're looking for trouble.
First of all, you need to handle your own primary key generation, because when inserting records on different sites, primary keys can/will be the same. Unique primary key generation is not easy to accomplish.
Furthermore, you need some conflict resolution. Updates or Deletes made on either side have to be reflected to the other site. Often, you cannot solve conflicts without user intervention.
My advise: look at built-in (two-way) replication, native to the database. It will save you a lot of headache.
Upvotes: 1
Reputation: 4434
It's always a good idea to have a last change field (date) on your records. Keep in mind that, if you start to synchronize, you have to take care of conflicts.
If both sides can insert, use a partitioning scheme for your primary keys. Example: Site A starts from 1000000000, Site B from 2000000000 (make this numbers large enough or simply divide your primary key size by the number of concurrent sites).
Rough synchronize plot:
Upvotes: 2