通过Xcode连接到mysql - appstore会允许吗?

时间:2013-02-17 04:29:30

标签: mysql database xcode

我是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但似乎很难...... :(

1 个答案:

答案 0 :(得分:1)

在您的应用程序中没有使用外部数据库资源的规则。我一直使用这种方法来包含不断变化的额外数据,这些数据无法在本地存储。但是,您的设备上没有PHP服务器,因此要完全执行此操作,您需要连接到远程服务器。

如果你已经完成了这一切,那么本地的所有人都可能想在SQLite上读一点,如果你可以做MySQL,那么你可以很好地使用SQLite。

相关问题