Reputation: 51
I'm very new to obj-c, and I'm doing this app where you click an annotation, which takes you to the country. I want to connect to MySql with an external php script:
<?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;
?>
and here is my button in 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];
}
How do I print out my results? and is this at all legal? Will appstore allow this? Is there another way to do it? I know SQLite but it seems very difficult ... :(
Upvotes: 0
Views: 339
Reputation: 3558
There is no rules against using outside database resources in your application. I use this method all the time to include extra data that is constantly changing that can't be stored locally. However, you do not have a PHP server on your device, so to do this fully you'll need to connect to a remote server.
If you are dead set on doing it all locally might want to read up a bit on SQLite, if you can do MySQL you'll be fine working with SQLite.
Upvotes: 1