Retrieving data from a remote database
could someone please explain to me the process of retrieving data from a remote database? I understand how to parse data from sqlite to an iPhone appl开发者_如何学Cication however remote databases seem to be more complex. I tried to do research however i get confused about web services,clouds and other words that im not familiar with. So far i gathered that i need to use JSON to convert the data from the database into the appropriate format that is displayed on a php page? then the iPhone application connects to that page and retrieves the data?
Would someone be able to give me a brief explanation (also what database can be used with JSON? in this instance)? would me much appreciated (also if someone has any tutorials/articles about this would be grateful). Sorry if im totally wrong, trying to learn...
That are many ways to build a system where you have a client application that retrieves data from a "remote" system that runs a database. You have many many choices as to what the server runs, and what the client is... and there is a world of technologies involved in this...
Since you are interested in learning, I would suggest you to take into consideration a very common architecture for such systems and dig into it.
One such example is LAMP (Linux, Apache, MySQL, PHP) and you can find a good tutorial at this site.
The tutorial covers everything you need, from setting up the systems, to retrieving the data and passing it back though the web; it's step by step and pretty easy to follow. The only thing that is not covered is JSON, but JSON in the end is just a format to pass data back and forth, and you can easily learn the basics about it with this tutorial.
Finally, I would suggest looking at how building an iPhone app getting JSON data. This would be the point where you join the two previous tutorials.
If you have a web service protocol on the server side, you can use JSON based web service to retrieve your data. If you follow any JSON tutorial, you can see JSON is just a text representation of the data.
Or you can simply use a post request to your server, which can response by simple XML with your own defined tag. So that you can use NSXMLParser to parse the data in your iPhone and decode information from there.
Any kind of database in the remote site will work. I prefer the free open source MySQL database.
With JSON web servie, you need some JSON converter for your database in the server side and also in the client side. A good open source client tool is SBJSONParser.
But if you use XML, you can define your own tag to encode and decode you database fields and information.
精彩评论