title: Unable to load JSON into D3.js from MySQL using PHP
body: <p>I am retrieving contents from my database(MYSQL) in PHP. The following is my PHP script:</p>
  
  <pre><code>&lt;?php
  $username = "**";
  $password = "**";
  $host = "**";
  $database="**";
  
  $server = mysql_connect($host, $username, $password);
  $connection = mysql_select_db($database, $server);
  
  $myquery = "
  SELECT  * FROM  data1
  ";
      $query = mysql_query($myquery);
  if ( ! $query ) {
      echo mysql_error();
      die;
  }
  
  $data = array();
  
  for ($x = 0; $x &lt; mysql_num_rows($query); $x++) {
      $data[] = mysql_fetch_assoc($query);
  }
  
  echo json_encode($data);
  
  mysql_close($server);
  ?&gt;
  </code></pre>
  
  <p>The output is a perfectly formatted JSON Object:</p>
  
  <pre><code>[{"ID":"1","Country":"India","Value1":"100","Value2":"200"},{"ID":"2","Country":"India","Value1":"230","Value2":"800"},{"ID":"3","Country":"USA","Value1":"30","Value2":"300"},{"ID":"4","Country":"Sri Lanka","Value1":"320","Value2":"330"},{"ID":"5","Country":"Sri Lanka","Value1":"120","Value2":"90"},{"ID":"6","Country":"Sri Lanka","Value1":"420","Value2":"890"},{"ID":"7","Country":"China","Value1":"20","Value2":"890"},{"ID":"8","Country":"China","Value1":"430","Value2":"999"},{"ID":"9","Country":"Canada","Value1":"200","Value2":"319"},{"ID":"10","Country":"Canada","Value1":"1000","Value2":"29"}]
  </code></pre>
  
  <p>I want to use this JSON object as input to my D3.js graph.</p>
  
  <p>When I try to create my D3 chart I get the error in my browsers log:</p>
  
  <pre><code>SyntaxError: Unexpected token &lt; in JSON at position 0(…)
  </code></pre>
  
  <p>The following is my D3 code where i invoke the PHP file and try to parse the JSON:</p>
  
  <pre><code>d3.json("1.php", function(error, data) {
  console.log(error);
  //parsing operations
  
  });
  </code></pre>
  
  <p>Any pointers would be appreciated. Thanks</p>