php - Echoing an array using json_encode -


using javascript application making server side request search functionality. works queries, not others.

for queries request returns no response, despite fact testing query in workbench returns thousands of records. tried turning on errors - no errors generated. tried increasing memory limit - that's not culprit. tried output pdo errors/warnings - nothing generated, pdo returns records, verified using var_dump, shown below.

so conclude, in below code, seems work flawlessly, until final line responsible encoding array json object - echos nothing.

i appreciate 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 * business name '%university%' group id";  $query = $db->prepare($sql); $query->execute(); $results = $query->fetchall(); //query returns 5000+ records in under second in workbench  $headers = array('business', 'city', 'state', 'zip', 'phone');   $json = array("results" => $results, 'headers' => $headers, 'query' => $sql); var_dump($json); //prints   echo json_encode($json); // echos nothing! 

edit:

use utf8_encode() json_encode() mentioned here (special apostrophe breaks json)

or

$dbhandle = new pdo("mysql:host=$dbhost;dbname=$dbname;charset=utf8", $dbuser, $dbpass,array(pdo::mysql_attr_init_command => "set names 'utf8'")); 

will parse data in utf8.

old

what's result if ?

echo json_encode($results); //scratch //$json = array("results" => $results, 'headers' => $headers, 'query' => $sql); //var_dump($json); //prints  

may run out of memory? try 100 results. know experience other projects json_encode can consume shared server's ram.

sorry if not helpful me can't test code, have us.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -