Synchronize SQLite / Android database table with remote MySQL database (via PHP)

I try to create a SQLite database when I first run the program with a single table containing 7 rows, which is designed to map to a table in a MySQL database on a remote server. So my thoughts are:

(1) At the first launch of the application, create a database, a table and the number of rows with the necessary entries.

(2) In all runs (including the first), try the remote MySQL database (over PHP), which contains a table with a timestamp column, and if the timestamp conditions are met (i.e. a new record was placed in the database), all records will then be added to the SQLite database on the Android phone.

If someone can point me in the right direction or give me the base code for any aspect of this, that would be great - thanks.

+4
source share
2 answers

Well, there are no magic bullets to sync Android with the database in the cloud. Since you are dealing with only 7 lines, I would use AsyncTask and an http client to send a request for receipt to your php page and return 7 lines and timestamps as a json document. Then I will query your local sqlite db and get the rows and timestamps from there. Then you can iterate over 7 rows and update sqlite as needed. It will be pretty easy.

If you want to use a different database, you may need to examine couchDB, they have an android client (in beta) that will sync with couchDB in the cloud. You can create couchDB on cloudant.com for free. Go google "couchbase android" if you want to use this method.

+3
source

Agree with nickfox that if it's just 7 lines, something simple like AsyncTask would be a good way.

However, if you think that there may be more data to synchronize, and you are looking for options, I will add one more: Oracle Database. You can use the Oracle Database Mobile Server to synchronize data between a SQLite database and an Oracle database running elsewhere.

It gives you the best of both worlds - light weight, easy to use and deploy SQLite database and applications on your Android device, fully functional, scalable high-performance Oracle Database running inside the corporation, or on a cloud and a mobile server between them to ensure that data remains in sync.

Good luck in finding and implementing.

0
source

Source: https://habr.com/ru/post/1346384/


All Articles