Using a javascript application I am making a server side request for a search functionality. It works for some queries, but not for others.
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.
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 json
object - it echos nothing.
I appreciate any assistance in resolving this.
PHP
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']) && !empty($_GET['searchBy']) ) ? $_GET['searchBy'] : 'name';
$sql = "SELECT * FROM business WHERE name LIKE '%university%' GROUP BY id";
$query = $db->prepare($sql);
$query->execute();
$results = $query->fetchAll(); //query returns 5000+ records in under a second in workbench
$headers = array('Business', 'City', 'State', 'Zip', 'Phone');
$json = array("results" => $results, 'headers' => $headers, 'query' => $sql);
var_dump($json); //prints successfully
echo json_encode($json); // echos nothing!