dongxian3418 2018-04-16 18:18
浏览 72
已采纳

将Base64图像插入到PHP PDO阵列中

I'm trying to insert Blob images retrieved from MySQL into an array using a while loop.

The database statement selected all images then i need to pass them all into an array.

So in theory, i should have an array of base64 encoded image corresponding to each record from my database.

Any help will be appreciated.

$sql = "SELECT img from artistlocation";

    try{
        $db = new db();
        $db = $db->connect(); 
        $stmt = $db->query($sql);
        $data = array();
        while($result = $stmt->fetch(PDO::FETCH_OBJ))

        {
            //$result = base64_encode(); ---- Something here im guessing
            $data[] = $result;
        }
       print_r ($data);
    }
    catch(PDOException $e){
        echo '{"error": {"text": '.$e->getMessage().'}';
    }
  • 写回答

2条回答 默认 最新

  • doubengshao8872 2018-04-16 22:41
    关注

    So the answer to this question came from AbraCadaver.

     $sql = "SELECT img from artistlocation";
    
        try{
            $db = new db();
            $db = $db->connect(); 
            $stmt = $db->query($sql);
            $data = array();
            while($result = $stmt->fetch(PDO::FETCH_OBJ))    
            {
                $data[] = base64_encode($result->img);
            }
    

    Thanks guys for the help!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大