• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 716 Replies
    2026 Replies
  • 331 Replies
    1928 Replies

Offline SQL sync

User avatar
muttley1968
Hardcore Programmer
Posts: 624

Offline SQL sync

Sun Aug 11, 2019 1:02 am

I have a client who has asked me to work on 2 seprate projects, one a website/app the other a desktop version of said app.
The website is php, html, jquery etc.... standard stuff.

What I was wondering is would it be possible to add offline syncing to that site and kill 2 birds with one stone.
I am not really sure how/where to start though.

I have a few basic ideas but nothing to run with yet.
1 - Maybe downloading the SQL DB as a SQLLite via a button that Syncs
2 - Maybe creating a cookie that holds all info as an array and syncing that every x minutes.

Neither of those seem to great of an idea (also dbs are not in need of security so to speak, their only info is fully displayed on site anyway)

User avatar
CodenStuff
Site Admin
Posts: 4386

Re: Offline SQL sync

Tue Aug 13, 2019 7:14 pm

You could output the online DB to a JSON file via PHP and then have the desktop app read and display the JSON whoever you want.

Basic example of PHP script:

Code: Select all

<?php

$DBConnection = mysqli_connect($servername, $username, $password, $dbname);

$sql    = "SELECT * FROM tablename";
$result = mysqli_query($DBConnection, $sql);

if (mysqli_num_rows($result) > 0) {
    $rows = array();
    while ($row = mysqli_fetch_array($result)) {
        $rows[] = $row;
    }

    echo json_encode($rows);
} 

mysqli_close($DBConnection);

?>
Comathi posted a good tutorial about reading JSON in vb.net:
viewtopic.php?f=38&t=11520

You could then, with a little work, reverse it and use something like POST/GET to send and update the online data from the app.

Hope that helps.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.

User avatar
Filip
Coding Guru
Posts: 834

Re: Offline SQL sync

Fri Aug 16, 2019 1:04 pm

Cookies won't help you much considering they can store up to 4 MB of data. While HTML5 local storage gives more generous 10 MB of data storage, that can still be a limiting factor. The best idea, as suggested would be use JSON data exchange. I'd create a REST API services which could serve both website and desktop application. Desktop application could store data locally in file system to enable offline access.
CodenStuff wrote:Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D

Post Reply

Return to “Help & Support”