Jeff
Jeff

Reputation: 2838

Calling remote php functions from an iPhone app

Anyone have any suggestions on how to set up both the php and the cocoa side of calling php functions? As a quick idea of what I want to do, I want to be able to to populate two tables with data and add/remove data from the db. So I want to set up a few functions in php that I can call from my iPhone code that will return values from my queries. I should note that my db is MySQL.

Mostly I'm interested in the syntax so if you have any code examples that I can play around with that would be super helpful.

Thanks in advance!

Upvotes: 6

Views: 5159

Answers (1)

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181460

Well, to get some data over HTTP protocol in iPhone, you could use:

NSString *urlstr = [[NSString alloc] initWithFormat:@"http://www.yourserver.com/yourphp.php?param=%d", paramVal];
NSURL *url = [[NSURL alloc] initWithString:urlstr];
NSString *ans = [NSString stringWithContentsOfURL:url];
// here in ans you'll have what the PHP side returned. Do whatever you want
[urlstr release];
[url release];

Now, on the PHP, you can return the data the way you want. I.E., and XML which you will then parse on the iPhone side.

Upvotes: 8

Related Questions