gpt4 book ai didi

php - 从 iPhone 应用程序调用远程 php 函数

转载 作者:可可西里 更新时间:2023-11-01 06:44:23 24 4
gpt4 key购买 nike

有人对如何设置调用 php 函数的 php 和 cocoa 端有任何建议吗?作为我想要做什么的快速想法,我希望能够用数据填充两个表并从数据库中添加/删除数据。所以我想在 php 中设置一些函数,我可以从我的 iPhone 代码中调用这些函数,这些函数将从我的查询中返回值。我应该注意到我的数据库是 MySQL。

我主要对语法感兴趣,所以如果您有任何我可以尝试的代码示例,那将非常有帮助。

提前致谢!

最佳答案

好吧,要在 iPhone 中通过 HTTP 协议(protocol)获取一些数据,您可以使用:

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];

现在,在 PHP 上,您可以按需要的方式返回数据。 I.E. 和 XML,然后您将在 iPhone 端对其进行解析。

关于php - 从 iPhone 应用程序调用远程 php 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/666534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com