我对obj-c非常陌生,我正在做这个应用程序,你可以点击一个注释,它会带你去这个国家。我想用一个外部php脚本连接到MySql:
<?php
include("connect.php");
$land = $_GET['land'];
$res = mysql_query("SELECT * FROM lande WHERE name = '$land'");
$row = mysql_fetch_array($res);
$flag = $row['flag'];
echo $flag;
echo $land;
?>下面是我在Xcode中的按钮:
-(void)button:(id)sender {
if (mapView.selectedAnnotations.count == 0)
{
//no annotation is currently selected
return;
}
id<MKAnnotation> selectedAnn = [mapView.selectedAnnotations objectAtIndex:0];
country_title = selectedAnn.title;
UIViewController* Countries = [[UIViewController alloc] initWithNibName:@"Countries" bundle:[NSBundle mainBundle]];
NSString *strUrl = [NSString stringWithFormat:@"http://localhost:8888/app/country.php?land=%@",country_title];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strUrl]];
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];
NSLog(@"%@",strResult);
[self.view addSubview:Countries.view];
}如何打印我的结果?这是合法的吗?appstore会允许这样做吗?有没有别的办法呢?我知道SQLite,但它似乎很难…:(
发布于 2013-02-17 12:46:44
在您的应用程序中没有禁止使用外部数据库资源的规则。我一直使用这种方法来包含不能在本地存储的不断变化的额外数据。但是,您的设备上没有PHP服务器,因此要完全完成此操作,您需要连接到远程服务器。
如果你已经下定决心要在本地完成所有的工作,那么你可以在SQLite上多读一点,如果你能使用MySQL,那么使用SQLite就没问题了。
https://stackoverflow.com/questions/14917984
复制相似问题