我知道关于 SQL Blob 和 PHP JSON 有类似的问题,但我不知道如何根据我的代码将 SQL Blob 作为 JSON 返回。
我正在将网站上的 pdf 上传到数据库,我想在 android 上查看此 pdf,但如您所见,数据 - 链接/blob- 为空。
这是返回给我的:
{"file":[{"id":"1","batchid":"121001","name":"dmxsuits.pdf","mime":"application/pdf","size":"263883","data":null,"created":"2013-08-05 03:29:38"}],"success":1}
我的PHP代码:
<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$result = mysql_query("SELECT * FROM file ORDER BY batchid DESC") or die(mysql_error());
if (mysql_num_rows($result)>0) {
$response["file"] = array();
while ($row= mysql_fetch_array($result)) {
//temp user array
$pdfFiles = array ();
$pdfFiles['id'] = $row['id'];
$pdfFiles['batchid'] = $row['batchid'];
$pdfFiles['name'] = $row['name'];
$pdfFiles['mime'] = $row["mime"];
$pdfFiles['size'] = $row["size"];
$pdfFiles['data'] = $row['data'];
$pdfFiles['created'] = $row['created'];
array_push($response["file"], $pdfFiles);
}
//success
$response["success"] = 1;
//echoing JSON response
echo json_encode($response);
} else {
$response["success"] =0;
$response["message"] = "No pdf found";
echo json_encode($response);
}
?>