Connecting to web servers and processing SQL


Hey guys,

When I was working through this chapter, I notice that the database is residing locally. The web services chapter (21) does not store any data locally (no filepath). My question is, for those complicated apps (facebook, etc) in which you passes a lot of data between the server and your phone, how is the communication made. For example, do you use a NSURLConnection to connect to the web server? Then do you run a web application (php, aspx) like upload a picture and let the php/asp do the heavy database stuff? And then when it is done, the picture you see on the iphone, is that a local copy or is it being hold in a NSDataArray (?) and loaded into an image view?

Is it possible to create a connection to a web server and pass along database commands like sql? Or the best way to accomplish something like that?

A little bit of background, my only experience with objective C is from this book. I am tasked to develop an enterprise application involving talking to databases via wifi and other stuff. It involves multiple teams in multiple departments but I’d like to at least understand the bits and pieces that will make it smooth.


Great book!


SQLite is for local data. You can certainly get data from a SQL server remotely and cache it in a SQLite file - but SQLite won’t help you grab data from a server.

“Facebook” is actually the Facebook server, which holds all of the data (not truly on one “server”, but that is besides the point) and allows HTTP connections. Clients connect to this server and make web service calls like “get profile”, “login”, “get photo album”. Applications like the Facebook iPhone app send these web service requests to the Facebook server, and it returns data (an HTML page, an image, profile information, etc.).

According to Facebook API guidelines, you aren’t allowed to cache a whole lot of data from Facebook. So, let’s say you want to use the Facebook iPhone app to view a friend’s profile. You open up the app, and you are logged in - this login process is you sending your login/password to the Facebook servers via a web service request. Then, you open up your friends list and your friends are displayed - the retrieval of your friends list is done by a web service request to the Facebook server. You select one of those friends - same thing.

Also, MySQL/PostgreSQL/Oracle solutions have C APIs that you can execute SQL commands from an iPhone client on a remote server that is hosting the database.

The new cool thing to do, however, is the former solution of exposing web services for tasks that you would like clients to be able to do.