我直接在数据库中保存我的图像(是的,我已经读过了,知道最好保存图像的路径)。问题是选择图像字段,这是一个blob返回null到我的JSON。我已经读了不少相同查询的stackoverflow链接,但仍然没有一个明确的解释/收到的答案已经能够帮助我。我使用base_64编码,但这样做时,网页上没有显示任何内容。
如果您能为我指出正确的方向,我将不胜感激。
这是我代码的一部分:
header("Content-Type:application/json");
//select query
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
if (!empty($rows))
{
$encode = array("StudentsList" => $rows);
//$json_response=json_encode($encode);
$json_response=base64_encode($encode);
echo $json_response;
echo json_last_error(); //Returns 0
}
如果你需要json数据请使用json_encode
例子echo json_encode($json_response);
和阅读PHP手册
http://php.net/manual/en/function.json-encode.php