user2727195
user2727195

Reputation: 7330

pdo/json longtext sometimes return as null

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

Upvotes: 1

Views: 813

Answers (1)

zerkms
zerkms

Reputation: 254896

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

In that case json_encode returns null.

Upvotes: 2

Related Questions