title: Echoing an array using json_encode
body: <p>Using a javascript application I am making a server side request for a search functionality. It works for some queries, but not for others. </p>
  
  <p>For some queries the GET request returns no response, despite the fact that testing the query in workbench returns thousands of records. I tried turning on errors - no errors are generated. I tried increasing memory limit - that's not the culprit. I tried to output PDO errors/warnings - nothing generated, the PDO actually returns the records, I verified this using var_dump, as shown below. </p>
  
  <p>So to conclude, everything in the below code, seems to work flawlessly, until the final line that is responsible for encoding the array into a <code>json</code> object - it echos nothing.</p>
  
  <p>I appreciate any assistance in resolving this.    </p>
  
  <p>PHP</p>
  
  <pre><code>error_reporting(E_ALL);
  ini_set('display_errors', 1);
  ini_set('memory_limit', '2048M');
  $db = new PDO('mysql:host=localhost;dbname=mydb', 'root', '');
  
  $search = $_GET['search'];
  $searchBy = ( isset($_GET['searchBy']) &amp;&amp; !empty($_GET['searchBy']) ) ? $_GET['searchBy'] : 'name';
  
  
  $sql = "SELECT * FROM business WHERE name LIKE '%university%' GROUP BY id"; 
  $query = $db-&gt;prepare($sql);
  $query-&gt;execute();
  $results = $query-&gt;fetchAll(); //query returns 5000+ records in under a second in workbench
  
  $headers = array('Business', 'City', 'State', 'Zip', 'Phone');
  
  
  $json = array("results" =&gt; $results, 'headers' =&gt; $headers, 'query' =&gt; $sql);
  var_dump($json); //prints successfully 
  
  echo json_encode($json); // echos nothing!
  </code></pre>