How does a server respond to a iOS device? [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
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.

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,

Recommendations for processing incoming data on a web server [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
Apologies for the general question, but it is an area I am having trouble even starting with.
I'd like to write a basic android app for a smart phone that sends a simple string over HTTP to a web server.
The client side of this is fine, but I don't know where to start with the web server part - here are my questions:
On the server side, how do you capture the data received on the web server from the smart phone? Is there a recommended programming language or script where I can capture the string sent from the smart phone?
for such a simple task, do i still need a full web server, or is there a recommended lightweight one?
Is there a way of testing where I can send a string to the webserver, and a webpage can print out a list of strings it receives in real time? Would Ajax be appropriate for that?
Thanks a lot, any guidance much appreciated.
As #cybermonkey said, you should communicate via HTTP POST. Http Post lets you send data (large bits of data), you can use the headers actively to determine response status etc.
When using POST, I would recommend transporting the strings in JSON-format. JSON Allows you to serialize and deserialize objects, arrays and strings. Can be serialized and deserialized at both ends, so you can transmit data in both directions.
You need a language to receive the data from the mobile app. I'd recommend either the language ASP.NET or my personal favourite PHP. They are both decent web-programming languages.
In order to run these services you need a web-server. There are alot of web-servers out there. The most popular and easy to use is probably Apache / httpd. (Nginx can also be recommended - but is more difficult to work with).

How to get data from MySQL database to Android 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 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.

Parsing JSON vs. Parsing XML in an IOS project [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
In the backend of my IOS project, the admin is saving the data into a DB or in an XML file. So whenever he wants, he can simply add an entry.
In the IOS app, I want to retrieve the data.
If I use XML, I can directly parse the XML file, since data are already in XML format (when admin added the value, the XML file got updated).
If I use JSON, I have to connect to the DB, get the result of the query and then encode it into JSON.
So, what do you think would be faster, in terms of the response come into phone.
Is there any other option that I didn't take into account?
I have read all of these similar questions:
JSON and XML comparison [closed],
What's better: Json or XML (PHP) [closed],
JSON or XML: Just Decide (April 2012; by Mark Nottingham)
and many more, but I want to ask something specific for my project.
It depends on lots different things:
amount of data
cpu time needed to generate the data
network bandwith/latency
mobile phone's hardware
...
But because generally mobile network is the bottleneck, probably the less redundant transfer will be the most efficient. And it is json in this case.

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