Connect android app with the database from a Website
Asked Answered
I

5

7

I need the users to register to my website with login and password.

basically i need to do the following

1.Connect android app with the database from a website.

2.Store some information into the database.

3.retrieve some information back from the database.

I have already experience with the standard sqlite build in android apps. The problem is, I need to let people register my website and retrive some information

Insipience answered 5/3, 2012 at 7:36 Comment(1)
Possible duplicate of Sync Android with a website database?Infeld
B
11

To store or retrieve any information stored on a Database on a web server, you will need to create a simple web service that will pass the requests to the database and then return the results from the database back to Android in a format Android can understand. You can typically send the data in POST or REST and then retrieve the data in JSON format.

There is a very good example of how you could achieve that using PHP here. Here you would send requests from Android to the PHP script(hosted on the server) using POST and then the script would return the results in JSON format, which in turn can be parsed by Android to get the desired result.

This is the basic method in which complex web services like twitter, facebook and the like operate. Most of the interaction is done with REST & JSON.

Bradski answered 5/3, 2012 at 7:48 Comment(2)
thanks i found an answer here but i dontt know how to go about with it #6232133 please help.Insipience
great and perfectly explained answer. thanksDoze
S
4

Usually you shouldn't directly connect to a database from an app because:

  • you have to store your database username/password in your app (everyone who is able to use a decompiler will get it very quickly)
  • once you have the username/password, you are able to do anything with the database

Based on these points I would recommend you to put a webservice between your app and the database. This webservice could be programmed in any programming language you like. It should protect your database from unintended requests on your database.

Your app then connects to your webservice, the webservice validates the user input and stores it in the database. When you'd like to receive some data from database, you just connect to the webservice and ask for data.

Stentorian answered 5/3, 2012 at 7:47 Comment(1)
thanks i found an answer here but i dontt know how to go about with it #6232133 please help.Insipience
A
1

The Best way would be to use Web-Services and implement them to handle all the Sql Queries sent from your client android Devices.

Anther answered 5/3, 2012 at 7:45 Comment(8)
thanks i found an answer here but i dontt know how to go about with it #6232133 please help.Insipience
What is web- services how to use itInsipience
Actually, you have two parts i.e. a Client part(your android device) and a Server part (where your database and everything exists), in order to access your database and provide your Client Code the Data Fetched from the Server you require a Webservice, they can be developed in .net php, java etc.Anther
hey you mean to say i need write a php which acts a medium between mydevice and databaseInsipience
Yes, exactly thats what i meanAnther
k but one question is in the php i have the code as mysql_connect("localhost","root","");.When the user enters details and clicks on submit now it goes to my website where i have this php.From here how will it go the the localhost since the database is in one machine and not in website?Insipience
Actually i am not well versed with Server side languages, you can google it and go through the Docs available thereAnther
Usually, the server which is running your PHP script usually hosts your database too. So in the usual case you connect to the database via "localhost". If you really host the database ona other server, you have to enable external database access on the DB server.Stentorian
D
1

You could use SQLLite to access the database but I don't know if its too safe for registering as you're required to supply sql database password.

Deloresdeloria answered 5/3, 2012 at 7:47 Comment(1)
thanks i found an answer here but i dontt know how to go about with it #6232133 please help.Insipience
S
1

You can use google firebase and Json for your project you just need to host your web-based project and you can Access your shared database. but you should make sure the database which you are using is shared a database .

Soutane answered 4/1, 2018 at 4:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.