【发布时间】:2016-08-03 15:54:36
【问题描述】:
我正在尝试从 MySQL 中的表中检索所有数据并将其添加到数组中。
我想将 blob 转换为编码字符串并将其添加到包含其他两列的数组中,然后将其作为 JSON 字符串返回。请参阅下面的我尝试的代码:
<?php
//Importing Database Script
require_once('dbConnect.php');
//Creating sql query
$sql = "SELECT * FROM picture";
//getting result
$r = mysqli_query($con,$sql);
//creating a blank array
$result = array();
//looping through all the records fetched
while($row = mysqli_fetch_array($r)){
//Pushing name and id in the blank array created
array_push($result,array(
"pictureID"=>$row['pictureID'],
"listingID"=>$row['listingID'],
"listingImage"=>$row [base64_encode('listingImage')]
));
}
//Displaying the array in json format
echo json_encode(array('result'=>$result));
mysqli_close($con);
代码当前返回的 blob 图像为空值。
【问题讨论】:
-
试试
"listingImage"=>base64_encode($row['listingImage']) -
当然,如果您按照应有的方式将文件保存在文件系统上,那么所有这些混乱都是可以避免的。
标签: php mysql arrays base64 blob