I have one application in two version: the online version and the offline version(USB).
How can I update the online version after some change in the offline database?

Dani AI

Generated

Short primer: the most reliable pattern is not manual export/import but a small, secure push-sync workflow — the USB app records changes locally and pushes only the deltas to an online API when a real connection exists. This keeps the offline UX simple (no manual imports) and avoids the fragility of file-based copy or browser-only “is it online?” checks. ’s export/import idea works for small one-off jobs, and was right to flag connectivity detection — but combine those ideas into an automated sync with clear rules.

Practical design (high level):

  • Track changes locally (preferred: change_log table, or columns like last_modified + synced flag). For new records created offline use UUIDs or temporary negative IDs and map them to server IDs on first sync to avoid collisions.
  • Implement a server-side HTTP API that accepts a compact JSON batch of changes and applies idempotent upserts (MySQL INSERT ... ON DUPLICATE KEY UPDATE) inside a transaction. The API should return per-row status so the client can mark rows as synced only after confirmation.
  • Client detects connectivity with a short, non-cached request (use cURL with short timeouts and check HTTP status); when reachable, POST the unsynced batch, handle transient failures with retry/backoff, and log results.

Small examples (illustrative only):

SQL upsert

INSERT INTO items (id,name,qty,last_modified)
VALUES (:id,:name,:qty,:last_modified)
ON DUPLICATE KEY UPDATE
name=VALUES(name), qty=VALUES(qty), last_modified=VALUES(last_modified);

PHP client (send JSON via cURL)

$ch = curl_init('https://yourserver.example/sync');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($rows));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json','X-API-Key: TOKEN']);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);

Notes and cautions: always use HTTPS and an authentication token, validate input server‑side, mark rows synced only on server confirmation, and keep backups. If multiple devices edit the same records implement a merge rule (last_modified wins, or server resolves and returns conflicts). If installing MySQL on many USB sticks is impractical, consider a portable local DB like SQLite and translate its rows to the server during sync. This approach addresses the gaps in the thread (manual export fragility, unreliable connectivity checks, and ID collisions) and gives a repeatable, resilient sync path.

Recommended Answers

All 8 Replies

Does the offline version have access to the internet?

Best thing to do is to 'export' the required data from the database and then 'import' into the adjacent database.

You can use tools like phpMyAdmin, etc.

Hope that answers your question :)

Does the offline version have access to the internet?

Thanks to reply to my post.
basically I need my application to be install on USB for those who do not have internet connection. They can work off-line by recording data in the off-line MySQL db through the off-line application.
As soon as they have internet connection they should have the possibilities to upload (Update the on-line MySQL db).
for that purpose I want to implement a small interface to help them interact between the off-line and the on-line database tables.
is there some body who can help me?
Thanks for your help

Thanks to reply to my post.
basically I need my application to be install on USB for those who do not have internet connection. They can work off-line by recording data in the off-line MySQL db through the off-line application.
As soon as they have internet connection they should have the possibilities to upload (Update the on-line MySQL db).
for that purpose I want to implement a small interface to help them interact between the off-line and the on-line database tables.
is there some body who can help me?
Thanks for your help

I would use something like this:
http://forums.digitalpoint.com/showthread.php?t=918941&highlight=php+check+url+status#post8399126
every time the user opens the file. Upon "404 error" continue to work offline. Upon "successful response" open up online connection, proceed to compare and update online database, redirect the user to the online application.

You need to make a simple php/mysql interface that lets you updates values for a database.
Use it for both:

Offline:
Setup apache, phpMyAdmin, etc on their computers, plus the usb in.
Transfer files to htdocs.
Make changes where possible, done.
Transfer Back to USB.

Online is Online (if your host has phpMyAdmin - most do).

You need to make a simple php/mysql interface that lets you updates values for a database.

;) But his question is how to ?

I would use something like this:

every time the user opens the file. Upon "404 error" continue to work offline. Upon "successful response" open up online connection, proceed to compare and update online database, redirect the user to the online application.

Nice logic. But the above script didn't work for me. I opened a webpage(http://www.google.com) and then, executed the script. It said, "still alive". Then, I disabled my lan and tried again! It again said, still alive. Then when I switched off my modem, restarted apache and tried ' it said "cannot work in offline mode". I am not sure is it the firefox or the script.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.