ฉันได้พัฒนาบริการเว็บด้วย PHP มันใช้ฐานข้อมูล MySQL ในนี้ฉันใช้ JSON ฉันต้องการดึงข้อมูลจากบริการเว็บนี้ในแอพ iPhone ของฉัน ฉันใช้ฟังก์ชันซึ่งมีพารามิเตอร์ตัวเดียว ฉันจะใช้สิ่งนี้ใน iPhone ได้อย่างไร
บริการเว็บ:
<?php
echo getdata($_REQUEST['lastupdate']);
function getdata($lastupdatedate){
$json = '{"foo-bar": 12345}';
$obj = json_decode($json);
//print $obj->{'foo-bar'}; // 12345
$con = mysql_connect("localhost","un","pwd");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//print_r($con);
mysql_select_db("roster", $con);
$query = "select * from rates where LastUpdated = '".$lastupdatedate."' order by LastUpdated limit 1";
$rs = mysql_query($query) or die($query);
//print_r($rs);
while($row=mysql_fetch_assoc($rs)){
$record[] = $row;
}
$data = json_encode($record);
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
return $data;
}
?>
ฉันกำลังขอ URL: http://domain/t1.php?lastupdate=2012-09-01 01:00:00