views:

309

answers:

4

If I have make an application, how would I make it interact with a database on a server of mine? I'm kind of lost, and don't know where to start.

+1  A: 

You might try Apple's "Getting Started with Networking & Internet" or "Introduction to the URL Loading System", in addition to the Networking section of the iPhone Application Programming Guide. There are also several sample applications that handle networking of various types within the ADC's iPhone section.

Additionally, there are a number of open source iPhone applications out there that handle networking, including my own.

Brad Larson
A: 

I had a similar question regarding a rails app - the answers there may help you.

http://stackoverflow.com/questions/365868/what-is-the-best-approach-for-building-an-iphone-client-for-a-rails-app

But the answer really depends on your knowledge of iphone programming and server side programming, plus how your database is set up at the moment - but most likely you're going to need to write some kind of webservice / REST API that allows a remote client to do things with your database.

There are many frameworks available for that on the server side - if you're starting from scratch, ruby on rails may be a good choice.

On the iphone side, you'll probably want to start by reading up on NSURLConnection, and various request/response formats that you can use with it. I've found exchanging plists between the phone and server to be a pretty easy approach.

frankodwyer
+2  A: 

Vague question yields a vague answer.

It entirely depends on what kind of interaction you need. Lots of constant queries? Few and far between? Client side cache? Real time updates? All of these questions will impact the answer.

The easiest way is to go with an AJAX style HTTP based client/server type of interaction. Sticking a database behind a web server has been done about a bazillion times and, thus, you'll find lots and lots of examples and, even, solutions with a few google searches.

You don't really need to use JavaScript (the J in AJAX). Instead, send over an HTTP request that encapsulates your query and have the server respond with an XML document containing the answer.

If that won't work for you -- too much overhead, need to relay binary information (for which XML sucks), etc.. -- then you'll wan to go with more direct access to the database. That is harder and can range from porting a client library to the iPhone to creating your own wire protocol.

A significantly harder problem and you'll have to deal with networking issues -- firewalls, NAT, proxies, etc... -- that are generally already solved with HTTP.

Stick with HTTP until you prove that it won't work. Much simpler.

Search for "http request" in the iPhone docs. HTTP client APIs are included.

bbum
I think AJAX would be the choice for me. How would I do that? I am a newbie to developing, so could you point me to a tutorial or something?
A: 

http://ODBCrouter.com/ipad (new) includes free XCode libraries and Objective C objects that provide the industry standard ODBC programming interface. This lets you connect, send SQL queries and receive back binary data directly into your program variables. The server-side component (called ODBC Router) runs on Windows and costs about the same as a TV set, but the database servers themselves can run on Mac OS X, Windows, Linux, IBM iSeries or AS/400, Unix, NetWare, DOS and legacy mainframes with support for most revisions of MySQL, 4D, QuickBooks Pro, DB/2, MYOB, Empress, Oracle, SQL Server, MS Access, Excel, Navision, Firebird, Pervasive, Sybase, Pick, Universe, Informix, Ingres and SQLite among many others. There are some screenshots at that link to show it in action.

AugSoft Tom
While self promotion isn't specifically banned from StackOverflow, you will find that you do yourself more harm than good if all you do is hawk your stuff. Also, your answers are going to end up removed by the community as spam. No developer I know supports spammers.
Will