Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 403
Jeff Avatar asked Mar 20 '09 15:03

Jeff


1 Answers

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.

like image 198
Pablo Santa Cruz Avatar answered Sep 26 '22 11:09

Pablo Santa Cruz