将MySQL blob转换为base64并返回为JSON

时间:2017-05-30 11:54:12

标签: php mysql json

我想解码MySQL数据表中的blob值,并在php中通过json返回 为什么json是空的?

  $sth->execute($_REQUEST);
    $row = $sth->fetch(PDO::FETCH_ASSOC);
    $result = $sth->fetchAll();
    if(count($result) > 0) 
    {
        $rows = array();
        foreach($result as $r)
        {
              $rows[] = $r;
        }

        foreach($rows as $key=>$value)
        {
          $newArrData[$key] =  $rows[$key];
          $newArrData[$key]['Data'] =base64_encode($rows[$key]['Data']);
        }
        header('Content-type: application/json');
        echo json_encode($newArrData);
    }

0 个答案:

没有答案