سؤال

I've a table with content pulled from a pdf file page wise (separate row for each page). It works fine but some of my results are returned as null even though the content exists in the table row? Why some are returning as null?

$q = isset($_REQUEST['q']) && $_REQUEST['q'] != "" ? $_REQUEST['q'] : null;

$statement = $this->connection->prepare("SELECT number, content FROM page WHERE folio_id = :folio_id AND content LIKE :q");
$statement->setFetchMode(\PDO::FETCH_CLASS, get_class(new PageVO()));

if($statement->execute(array("folio_id" => $folio_id, "q" => "%" . $q . "%"))) {
    return $statement->fetchAll();
}

in my output file

header('Content-type: application/json');
echo json_encode(array("search" => $searchVO));

Screenshot attached. json

mysql database

After Adding Length Attribute length

هل كانت مفيدة؟

المحلول

It happens because some of your strings are not properly utf-8 encoded.

In that case json_encode returns null.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top