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条)

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据