views:

53

answers:

2

I am basically trying to retrieve some data from a MySql server, and display them on my iphone Let's say i have a table named "car" and i need to send 10 rows of my table to my iphone.

1- Is there any possible way to send an actual array of objects "cars" to my iphone. Or does it have to be a string.

2- If it has to be a string, what is the best format to use? XML or JSON, or any other format?

3- Is SOAP the same as a web Services? if not what's the difference?

4- What is the best language to use, to handle the data transfer between iPhone and database? is it a good idea to use php?

+2  A: 

1 - yes, you should serialize the array of objects on the server side and send it to iphone. Then deserialize it and use it.

2 - JSON or XML, both have good and bd things. Just use JSON for now. Any server language supports it (php, ruby, python) and you can use Apple or 3rd party JSON parser on iPhone

3 - SOAP is a way to serialize messages. Those messages are exchanged between client and server. The exposing of server functionality is called "Web Service"

4 - PHP, Ruby on Rails, Python (Django)...

Zepplock
ok i'm confused by answer 1, and 2. If it's possible to send an array of (custom) objects, then what's the point of using XML or JSON?
aryaxt
I'm not sure what you mean by "custom objects". Any object in "Objective Oriented Programming" sense can be serialized into something: XML, JSON, text file. Once you do that you can send it over the network. XML is usually used to present tree hierarchy where items have names, JSON is typically an array of hashed or hash of arrays and is presented as a collection of key/value pairs.
Zepplock
oooo ok so by serializing u mean converting array of objects to an xml, or jason string right?so SOAP is another way of formatting (serializing) a string just like xml or json?
aryaxt
Simply put, XML and JSON are ways to maintain data hierarchy. SOAP is built on top of XML and imposes certain rules on how to do it with an intent for the data to be sent over network.
Zepplock
A: 

To access a database I usually will send a request to a script (I use php, but there are lots of options) that interacts with my database and have the script send back xml in a plist format.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
<plist version="1.0">
<array>
    <string>item1</string>
    ...
    <string>itemn</string>
</array>
</plist>

If you don't need to send parameters to the script you can just use convenience methods such as initWithContentsOfURL: where the url is the script that will output the items from the database.

If you want to send binary data instead of the string you can use a NSURLConnection to get the NSData back form the server. You can then create an NSArray from the [NSPropertyListSerialization dataWithPropertyList:format:options:error:] method.

thelaws