First, I'd like to let you know my experience.
PHP - medium | Android/Java - medium | JSON - low | MySQL - low
I'm trying to make an app that will be able to connect to a MySQL DB, grab a specified row, and display it in my application.
I've been doing a lot of research, but feel like I still have a lot of unanswered questions. From what I read that doing a direct connection to the database should never happen. Is this true? Next, most people suggest writing something in php to connect the app to the database. My main question is where do I put this php code? On a website or in the android app (if that's even possible)?
If anyone has experience with this, do you think I should follow this tutorial? (I don't want to buy a domain if I don't have to)
http://www.helloandroid.com/tutorials/connecting-mysql-database
Client side:
and android app that basically uses the defaulthttpclient in java to establish connection to a php page hosted on a website by posting data to it(httppost).
and a json parser to read the retrieved data and display it.
server side:
a php script on the web server which accepts post data from the client, and retrieves data from MySQL database at the server and displays it, which can be read by the client as an httpresponse.
i hope that helps.
Create a web service to pull objects that contain data from your database. A WCF Service is a good choice.
Related
This question already has answers here:
Can an Android App connect directly to an online mysql database
(8 answers)
Closed 6 years ago.
I have a website already setup which uses mysql database. I want to know how can i connect my app to that database.
What i wanna achieve is that my app should make a request to find a table of a defined "ID" or name. The table contains links to images or image names. I want the app to retrieve those images and display them on the android app.
What are the ways this can be done?
Can I use PHP to develop an android app?
Android does not support MySQL out of the box. The "normal" way to access your database would be to put a Restful server in front of it and use the HTTPS protocol to connect to the Restful front end.
Have a look at ContentProvider. It is normally used to access a local database (SQLite) but it can be used to get data from any data store.
I do recommend that you look at having a local copy of all/some of your websites data locally, that way your app will still work when the Android device hasn't got a connection. If you go down this route then a service can be used to keep the two databases in sync.
The one way is by using webservice, simply write a webservice method in PHP or any other language . And From your android app by using http client request and response , you can hit the web service method which will return whatever you want.
For PHP You can create a webservice like this. Assuming below we have a php file in the server. And the route of the file is yourdomain.com/api.php
if(isset($_GET['api_call'])){
switch($_GET['api_call']){
case 'userlogin':
//perform your userlogin task here
break;
}
}
Now you can use Volley or Retrofit to send a network request to the above PHP Script and then, actually the php script will handle the database operation.
In this case the PHP script is called a RESTful API.
You can learn all the operation at MySQL from this tutorial. Android MySQL Tutorial to Perform CRUD.
Yes you can connect your android app to your PHP to grab results from your database. Use a webservice to connect to your backend script via ASYNC task and http post requests. Check this link for more information Connecting to MySQL
Use android vollley, it is very fast and you can betterm manipulate requests.
Send post request using Volley and receive in PHP
Basically, you will create a map with key-value params for the php request(POST/GET), the php will do the desired processing and you will return the data as JSON(json_encode()). Then you can either parse the JSON as needed or use GSON from Google to let it do the parsing.
I am making an application similar to that of apps such as pay by phone and paymobile, which are apps used to pay for parking instead of using a parking meter and having to display a ticket in your vehicle.
I need to start with the back-end (the database) and was wondering if SQL would be appropriate for this app.
As SQLite is stored on the system (the Database) there will be data such parking details and payment details.
Will I be able to send this data to say my laptop which will act as the server for the traffic wardens device to check number plates?
Or would I have to use a sql software that is not on the applications itself?
Any thoughts and suggestions would be much appreciated :D
SQL is perfect for back end database needs. You can various flavors of SQL like Oracle or MySQL on the back end. As far as the application data being sent to the server (your backend laptop), that will be taken care by the application level programming. For android, there are various ways to send data, using the native class AsyncTask or using third party libraries like Retrofit and Volley. You need to take a decision depending on the architecture of your app.
Try this
Create database on your server
Create Web API like .Net MVC on your server
Create connection between your Web API and your database
In your mobile app you can use webservice to get our put your data to database
You can encyrpt your data on your database to more safety
do not use SQLite , because it is unsafe to keep your important data.
I trying to post data from android SQLite database to MySQL database. I come cross many reference. My question is can I post data from Android SQLite database to MySQL database without Json? Json seem very complicated since I don't have a any Json knowledge.So far I can store data in SQLite. I need to post all my data to MySQL. Thank You.
It is a good question.let maximum people get benefit out of this. When you are using a mobile either it could android,IOS,windows no matter what ,the device has to interact with the server in order to exchange the data stored in the server.If you want to browse you need an active internet connection. can you browse without internet on a mobile?? i don't think that technology exist. Similarly, there are only two ways how you can interact with server from mobile devices. XML JSON Typically these act as a bridge between two canals.
XML:
The data can be transferred from mobile to server and from server to mobile using XML.This is the traditional one.May be first evolved technology.But it is heavy weighted.
JSON
This is the advanced technology. Very Light-weighted,quick and easy to learn.Easy to parse. JSON is the common framework that is being used now-a-days.
And when it comes to your question:
you cannot cross canals without a bridge or a boat. which is JSON or XML in your case.
Any tutorials out there on how to send and received data to and from a MySQL database hosted on a server using cPannel? I'm trying to make an android app that connects to the internet, and it needs to read and write data to and from the hosted database. The database is a MySQL one and is hosted on godaddy. I've been on the internet all day today looking, so any help would be greatly appreciated.
Well you need to write a webservice which will get the data from your mysql database and send it to your android app.
First of all you need a server which you have already. Create space to write php scripts there to interact withe the database that is hosted there.
Second Write a php script on your server which can retrieve the required data from the MySQL database. Encode the retrieved data inside a JSON object and send it back to your app. From your app you have to call the URL where the webservice is hosted, and the php script will do the interaction with the database, retrieve the results and send it back to your app in JSON.
Third - Follow the same method to send and retrieve data to server. Create multiple webservice as per your requirements.
This tutorial excellently illustrates what you are looking for. This example uses a local server. You can skip some of the steps there. Hope it helps. URL: http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
If you still got any questions, comment below. I will be happy to help.
Thanks!
I am new to Java and Android. I am just beginning work on an app that will save information to a server that someone else from within the same company can retrieve using the same app from a different android device. I know how to simply store data on a server using simple php scripts but this is a bit more complex and involves one user writing information to the server, while another user can see / download it. Within a company there would be multiple users who have acceess to this data. So my question would be, whats the best way to implement a company-wide database that ONLY members of the same company can have access to? Sorry if this seems obvious to some of you. I am just getting started and I have 7 books on android programming and none of them describe how to do quite what I am trying to do.
To do this you need to use Android network services to access data. In other words to retrieve a networked database information your device will connect to your service with a specified URL and arguments. In turn, the service will reply with the required data, say may be in XML format. All your app needs to do is parse the XMl and display the date as desired.
Same thing applies to putting data into the server, in this case however the data will be sent as arguments to the network service URL and the service will handle the persistence to a database.
My advise is to do a Google search of the keyword "Android Network Services".