How to get data from MySQL database to Android app [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
From my android app I want to get some data from my table containing two columns in my online MySQL database. Could someone explain me how to write a PHP script or something what I need that would respond to a call from my Android application by getting some values from my database and returning it to my app? And then how to call that function from my application and how to handle (save in my app) the returned data? HUGE HUGE THANKS in advance!

There's not a built-in MySQL connector for the Android framework, and even using an external jar for this is discouraged. The best way you can accomplish this is via a webservice in the remote server, so instead of sending direct MySQL queries to a database, you'd send a HTTP POST to the remote webserver (for instance, written in PHP, Python or whatever you want) and this would connect to the local database and make the query.
I think this example might help you.

When you make the http request to the php script, you handle the request based on the method you sent, GET or POST.So for example
$id=$_POST['id'];
From there you do whatever server side queries to get the needed information. When you are done, simply echo the response back. I would recommend using JSON as the format as its easier to deal with.
echo json_encode(array('success'=>true,'data'=>$data));

You can extend the SQLiteOpenHelper class to write your own sqlite helper interface.
Try following some tutorials on Android's site here.
Or follow a neat tutorial here from vogella.

Related

How can I read out of a MySQL database in xcode/swift [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I was wondering how could I read data out of my MySQL database into swift/xcode.
I searched all over the internet and i just need to know how to read out of a database that on my webhost. I do understand how PHP works, but I do not know everything about xcode.
If something isn't clear, feel free to ask.
Regards,
Jenoah
I can understand your problem. You can not execute MySQL queries directly from xcode. For that you need to have web-services.
You can create web-services in PHP or any other languages. Pass parameters in your URL (GET or POST). and use those params to deal with your database. Finally, output it in either json or xml.
Now, from xcode side you need to call that URL and fetch response from your json or xml.
There are bunch of libraries out there by which you can call web-services from xcode. I am not into ios programming so, I don't know that much about it. But, you have to create those services by your own. Hope this will help you.
I recommend you to post some parts of your code because your question is not specific.
With that information, I can only tell you that you have to connect your Swift code to a PHP file (using POST) and then in that .php file connect to the database. If you want to read the results from that database, you can use JSON to read the information.
If you show us your code we could helo you better.
Thanks,

Do I need a web API or normal webservice will do? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
My Android app calls for some data that I have stored in my database. I've worked with some Java Dynamic Web Apps, wherein they'll use cxf and write web APIs, catering to the requests. This seemed like the obvious idea for me to take up. So I wrote my REST API, used Jersey, and everything seemed to be working fine.
But then I checked out the cost of hosting a Java app on server, and then I decided to write the API in PHP. I thought that REST was basically just providing different URLs. But then I came across this tutorial here. In this tutorial, the author just makes call to normal PHP files, and that's it. I am echoing JSON encoded data in my PHP script, that I get back. This does not sound very RESTful to me. Maybe because I don't see /getClientInfo,addClientInfo kind of URLs.
Calling normal PHP scripts is just so normal. What did REST add to it?
In short: it does not matter. At all.
The actual API here is an HTTP interface. The web server this all runs on is the API. You're just dressing it up differently by using different URLs or possibly different protocols on top of HTTP, e.g. SOAP or such. But fundamentally nothing changes, you're making an HTTP request and you're receiving data back in an HTTP response, period.
REST is simply one way to structure your API's URL names and parameter conventions etc., and a way that makes sense in the context of HTTP. But it's not the only way and by itself REST doesn't do anything that's absolutely necessary or not doable any other way.

Website to IOS App [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a website that I've created using PHP, Mysql, and other (HTML, CSS, etc) and I'm looking into converting the website into a native Iphone App for the app store. I know quite a bit of Objective-C and have used X-code for a couple years but I'm confused about one aspect of it. I've never worked with databases from an app. The database that we have set up is just a good old fashion PHP and Mysql that we connect to. It holds all of the site's users and other information.
Therefore, what should I do about accessing this database on the phone? Is there a way to use Mysql or is there something else that I can use that would interact with the database separately? I know there is SQLite but does that work with Mysql or not?
Any tutorials or guides you could point me to also would be great. Thanks.
The simple answer is: don't connect an iOS app directly to the database. Think about it: you'd be embedding a username and password somewhere in the app's code, which some nefarious user will find a way to extract and exploit.
Much better way to do it: create a simple API on your website, then pass requests from mobile users through the API. Then your server handles all database connections, authentication of users, and so on, and you haven't put your database credentials in the hands of lots of unknown individuals.

How does a server respond to a iOS device? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I would like to know how a server, running MySQL, can respond to a iOS device if they had passed info through the URL. I'm a web developer helping a friend link his app with a server and it's database.
The set up:
MySQL on server
PHP
iOS device with app to access server's urls
Technique:
The webpage will extract the $_GET parameters from the URL and query the database with the parameters. How would I pass data (the database query's data) back to the iOS device from this PHP page?
Is JSON a solution? If my .php page encodes a JSON format, will the device be able to pick up the data that is returned from the database?
I don't really know what's happening backstage with apps like flickr api and such that lets iOS devices query a database and get url strings returned to retrieve pictures. Can someone elaborate on this?
The server response can be anything you want. It is common for the response to be data formatted as JSON. It can be XML, plain text, or proprietary binary format. It doesn't matter. The iOS app will get the response. As long as both sides agree on a format it can be made to work.
You can do this in any format you want, but one of the most common ways is JSON:
pass back a json object in php
<?php
echo json_encode($my_array);
?>
using the NSURLConnection class to make the request and the NSJSONSerialization class to convert your JSON response to a dictionary/array.

how to transffer data from website to android app and enable or disable it from website only? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
My team is going to make application in android having quizzes on mobile whose questions,options would be entered from my website. I want to be able to enable the new quiz from website end.
Going to code website in PHP. I'm good at wordpress so just wondering if I can do this in that only or not as I don't in what form I have to convert my data so that android can get it and use it in "native app"(not browser!!).
my job is only the website part I know how to make pages but don't know in what form I have to give quiz data and how to control enabling and disabling the quiz in mobile app
thanks for the help in advance...
There are several ways you can transfer data through different applications/technology.
Some ways that appear to be straight ahead to me:
The Android App can parse your generated HTML file directly and extract the questions and the options parsing the HTML tags.
The Android App can also connect to your website DB and get the information directly from that.
You can also expose your data creating a services using WebServices or ODATA, for example.
I have to say I've only ever dealt with Cordova for writing apps but if Cordova can do it...
In the app I wrote for an internal application I used an AJAX call (Cordova uses JS + HTML as its interface). My PHP server then returned a response my app could use (in my case, JSON) It sounds like this is what you want to know. Now your app team will have to tell you what format to send your response but it's possible to have apps do this.
This would have to be done in PHP(EDIT: or any other technology as such) since your team is working in PHP already. To enable/disable the "new quiz", the app would have to query the server for this information, which would come from the Database.

Categories