1

When there is no signal I use offline mode by storing data to the device (SQLite). After there is a signal I try to send the data to the Mysql server.

How can I send data from SQLite (offline mode) to MySQL server?

2
  • 1
    Are you using any webserver in the middle of your app and the database ? usually its done that way, your app sends / gets the requests from server, so wen offline just cache it to sqllite after get online just send it all to the server that will persist to the mysql database. Commented Jan 22, 2019 at 22:51
  • 1
    Ok i ll try.. many thanks Commented Jan 23, 2019 at 15:40

1 Answer 1

2

create a DB similar to your sqflite db's table in a remote server. then, create a rest api using your desired language(php is easy to start). then, when the app is connected to internet, use HTTP client to send the data to the remote server.

you can use a code like below for the post data call:

Future<dynamic> post(String url, {Map headers, body, encoding}) {
print(url);
print(body);
return http
    .post(BASE_URL+url, body: body, headers: headers, encoding: encoding)
    .then((http.Response response) {
  final String res = response.body;
  final int statusCode = response.statusCode;

  print(res);

  if (statusCode < 200 || statusCode > 400 || json == null) {
    throw new Exception("Error while fetching data");
  }
  return _decoder.convert(res);
});
}
Sign up to request clarification or add additional context in comments.

11 Comments

Is rest api like when we insert data to mysql server?
nope a rest api is just a url link accomplish the format of its specification, that maps the post request to the method in an application running at the server, that will insert your posted data to mysql server.
Basically its the same thing that I've told you in my previous comment :)
@DwiNurRohman, as Diago Garcia explained, rest api is a medium by which you send data to server, and the data gets inserted to mysql. you cant actually insert data any mysql database, from android. you need a medium for that. theres lots of example in the internet. check please. here is a [link[(codeofaninja.com/2017/02/create-simple-rest-api-in-php.html)
@diegogarcia and Starlut
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.