I have an iPad application that uses table view controllers to present lists of data. I want to connect these tables to data in a SQL Server. I have very little experience in this realm of programming and I am not sure where to begin. In the long run I’d like adding/editing/deleting data on the app to sync with the server as well. I understand that this is a very broad question, so I am mainly looking for suggestions to help me get started. I, for example, do not want to start researching and learning Core Data if it is not the framework that can accomplish my goal.
In short, how can I connect my application to a SQL Server so that I can access its data and sync it to a device? Any example code/walkthroughs would be much appreciated.
I am currently working in an iOS application that requires this same functionality. For mySQL database queries on the server, I am using server-side PHP scripts that can accept variables, such as the table name or database search term.
What I do is I make an HTTP GET request using objective-C’s NSMutableURLRequest, then have the server process the request (in PHP), and then return the database query results to my application in JSON format. I use SBJsonParser to parse the returned data into an NSData, and then an NSArray object.
An example of making an HTTP request in Objective-C:
There is more code that you need to add to actually respond to the request when it returns, and I can post an example of that if you would like.
I actually dont know if this is the best way to do this, but It has worked for me so far. It does require that you know PHP though, and I don’t you if you have any experience with it.
UPDATE:
Here is some sample code showing how to respond to the request. In my case, since I am getting a JSON encoded response, I use the SBJsonParser to parse the response.
Also add these methods, assuming you have an NSMUtableData instance variable titled receivedData.