title: Php webservice - call parameterised function from browser
body: <p>I have 1 function which is having 1 parameter.
     I want to call this function from browser.
     How can I call?
     It is giving me blank.
     When I write same code outside function , it is working.
     Please help me.
     I am passing this link to browser  "domainname ://ipaddress/test.php/mywebservice"</p>
  
  <p>i am using this code :</p>
  
  <pre><code>&lt;?php
  
  $json = '{"foo-bar": 12345}';
  
  $obj = json_decode($json);
  //print $obj-&gt;{'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;
  }
  ?&gt;
  </code></pre>
  
  <p>Result :</p>
  
  <pre><code>{'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; } ?&gt;
  </code></pre>
  
  <p>If I wirte:</p>
  
  <pre><code>&lt;?php
  
  $json = '{"foo-bar": 12345}';
  
  $obj = json_decode($json);
  //print $obj-&gt;{'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;
  
  ?&gt;
  
  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":""},]
  </code></pre>
  
  <p>Which is correct.</p>