与json的PHP Web服务

I am new to PHP & JSON, and based on a tutorial I made a simple web service which returns the contents of a table of a mysql db.

The output is in JSON and the database caracter set is UTF-8. my problem is that when I try to run this it throws me a 404 error, and doesn't show me where the error is. Any idea what might be wrong?

The PHP file is the following:

<?php
  ini_set("display_errors", 1);
  error_reporting(E_ALL);
  $link = mysql_connect($mysql_host,$mysql_user,$mysql_password) or die("cannot connect to the DB");
  mysql_select_db($mysql_database,$link);
  $query = "select...";
  $result=mysql_query($query) or die (mysql_error("error "));
  $num=mysql_numrows($result);
  $rows=array();
  while($r=mysql_fetch_assoc($result)){
      $rows[]=$r;
  }
  echo json_encode($rows);
?>

Any Idea? Thanks in advance

Add following line before json_encode()

header('Content-type: application/json');

That should solve your problem.

Are you sure you want use JSON? You can also use SOAP-NuSOAP and WSDL for creating a web service. See, for example, Create a PHP Web Service in 5 Minutes Using PHP SOAP and WSDL Technology and NuSOAP.

In this , I have written my php web service code. follow this. hope it will help you.

link :

http://stackoverflow.com/questions/12702128/json-parsing-in-iosphp