Access SQL database remotely from iPhone app
I am trying to access an SQL database remotely.
Can someone give me a hint o开发者_C百科r idea about how to do this in the iPhone?
Generally you wouldn't want to access it directly from your iPhone app, that would be messy and hard and potentially worse if you ever want to change your database and will require replicating a lot of work if you want to hook your database up with another app, maybe on another platform, in the future.
Exactly what you should do depends greatly on your db, the app and your requirements but look into creating some sort of web service that does the work of connecting to the db and parceling up the data that you want. If you're on SQL Server you coud look at a .NET webservice and you could get Visual Studio to do nearly all the work for you or if you're using mySQL then php may be the way to go. Consuming the data on the iPhone will be easy enough if you can get at it in json or XML format, get your webservice to package data up in one or both of these (most platforms will have handy sql table to json/xml functions).
The app then will want to be able to access the webservice through a URL using a regular HTTP get request (look at NSURLConnection) and then parse out the xml/json data for which there are handy libraries (the json one I use is http://code.google.com/p/json-framework/)
That should give you a general starting point, would need more specifics to give a better answer.
精彩评论