I'am developing an iPhone application to display data from php. Data are obtained from a Mysql database then encoded to JSON format in php file:
include_once 'connectionIncl.php'; if(function_exists($_GET['method'])){ $_GET['method'](); } function getSQLIntoJSONFormat() { $arr; $sql = mysql_query("SELECT * FROM pecivo"); while($pecivo = mysql_fetch_assoc($sql)){ $arr[] = $pecivo['typ']; } $arr= json_encode($arr); echo $_GET['jsoncallback'].'('.$arr.')'; } // --- http://127.0.0.1:8887/TeplyRohlik/pecivo.php?method=getSQLIntoJSONFormat&jsoncallback=? when i run this from browser, it returns correct data :
(["sejra","knir","baba","vousy","sporitelna25"]) Also, on iOS a have this code:
NSString * urlString = [NSString stringWithFormat:@"http://192.168.0.10:8887/TeplyRohlik/pecivo.php?method=getSQLIntoJSONFormat&jsoncallback=?"]; NSURL * url = [NSURL URLWithString:urlString]; NSData * data = [NSData dataWithContentsOfURL:url]; NSError * error; NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; NSLog(@"%@",json); And result is .... (null). I have no idea how to get this working...
mysql_*functions in new code. They were removed from PHP 7.0.0 in 2015. Instead, use prepared statements via PDO or MySQLi. See Why shouldn't I use mysql_* functions in PHP? for more information.