gpt4 book ai didi

php - 在 PHP 中从 MySQL 返回 blob 数据并转换为 base64_encode 以添加到数组

转载 作者:行者123 更新时间:2023-11-29 11:36:01 25 4
gpt4 key购买 nike

我正在尝试从 MySQL 中的表中检索所有数据并将其添加到数组中。

Click for Table columns structure

我想将 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"=>$row [base64_encode('listingImage')]

"listingImage"=> base64_encode($row["listingImage"]);

关于php - 在 PHP 中从 MySQL 返回 blob 数据并转换为 base64_encode 以添加到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36583386/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com