Skip to content Skip to sidebar Skip to footer

How To Have Android App Work With Mysql Online Database?

So I have an android app where users will be entering text and what not, and I want to store (and later retrieve) this info from an online database. Currently I have a LAMP server

Solution 1:

You'd need to find an MySQL client library that works for Android, or implement one yourself from scratch within your app, so that you could connect to MySQL's TCP socket and deal with the DB directly.

However, exposing MySQL to the 'net directly in such a fashion is highly highly risky. I strongly advise you to write a PHP middle-ware layer to act as a gatekeeper, otherwise your DB is likely to get cracked into and sucked dry.

Solution 2:

On your LAMP server you should be writing a web service API for your android application to talk to. Depending on what data you are sending/reading you'll have alot of security concerns to deal with. I won't go into all that here.

Once your server side is setup you can connect to your site using the DefaultHttpClient class. Something like this:

DefaultHttpClienthttpClient=newDefaultHttpClient();
HttpGethttpGet=newHttpGet("http://url.to.my.app.com");
HttpResponseresponse= httpClient.execute(httpGet);
// handle response

An alternative to running (and writing) your own web service would be to connect to something like a google apps backend. You still have some writing to do but much of the security concerns are easier to handle.

Post a Comment for "How To Have Android App Work With Mysql Online Database?"