1つのパラメータを持つ1つの関数があります。この関数をブラウザから呼び出したい。どうすれば電話できますか?それは私に空白を与えています。関数の外で同じコードを書くと、それは機能しています。私を助けてください。このリンクをブラウザ「domainname://ipaddress/test.php/mywebservice」に渡します
私はこのコードを使用しています:
<?php
$json = '{"foo-bar": 12345}';
$obj = json_decode($json);
//print $obj->{'foo-bar'}; // 12345
switch($_GET['function']) {
case 'specificFunction':
abc();
}
function abc
{
$con = mysql_connect("localhost","uname","Password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//print_r($con);
mysql_select_db("roster", $con);
$query = "select * from rates";
$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');
echo $data;
}
?>
結果 :
{'foo-bar'}; // 12345 switch($_GET['function']) { case 'specificFunction': abc(); } function abc { $con = mysql_connect("localhost","uname","Password"); if (!$con) { die('Could not connect: ' . mysql_error()); } //print_r($con); mysql_select_db("roster", $con); $query = "select * from rates"; $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'); echo $data; } ?>
私がしわがれた場合:
<?php
$json = '{"foo-bar": 12345}';
$obj = json_decode($json);
//print $obj->{'foo-bar'}; // 12345
$con = mysql_connect("localhost","uname","Password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//print_r($con);
mysql_select_db("roster", $con);
$query = "select * from rates";
$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');
echo $data;
?>
Result :
[{"Month":"July","Year":"2012","Rate":"1.20%","Short":"0.24%","Mid":"0.92%","Long":"2.30%","RateUnFormatted":"0.012","LastUpdated":"2012-09-01 01:00:00","PublishFlag":"M"},{"Month":"June","Year":"2012","Rate":"1.20%","Short":"0.23%","Mid":"1.07%","Long":"2.64%","RateUnFormatted":"0.012","LastUpdated":"0000-00-00 00:00:00","PublishFlag":""},]
どちらが正しい。