dongma7725 2016-05-10 07:41
浏览 144

从Oracle数据库中检索hugeblob图像给出了recorse id,PHP,Codeigniter

I am retrieving HUGEBLOB image from oracle database Using Codeigniter. When i Get the Image it gives Resource id #45.

My question is,

Why resource id is given? How to convert Recourse to string and display this image?

my code is,

public function get_image()
{
    $reg = $this->session->userdata['user'][0]['REG#'];
    /*$this->db->select("PIC");
    $query = $this->db->get_where("ADM_STUDENT",array("REG#" => "BET-FA07-012"));*/

    $query = $this->db->query("select * from ADM_STUDENT WHERE REG# = 'BEE-FA15-066'");
    $row = $query->row_array();
    echo "<pre>";
    print_r($row);
    //$this->output->set_header('content-type: image/jpeg');
    //print $row['PIC'];
    //echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['PIC'] ).'"/>';
}

Please help me i am stuck on here.

  • 写回答

1条回答 默认 最新

  • 普通网友 2016-05-10 15:04
    关注

    Refer to the PDO documentation on handling LOBS:

    PDO allows you to work with this large data type by using the PDO::PARAM_LOB type code in your PDOStatement::bindParam() or PDOStatement::bindColumn() calls. PDO::PARAM_LOB tells PDO to map the data as a stream, so that you can manipulate it using the PHP Streams API.

    Example 1 shows 'Displaying an image from a database':

    $db = new PDO('odbc:SAMPLE', 'db2inst1', 'ibmdb2');
    $stmt = $db->prepare("select contenttype, imagedata from images where id=?");
    $stmt->execute(array($_GET['id']));
    $stmt->bindColumn(1, $type, PDO::PARAM_STR, 256);
    $stmt->bindColumn(2, $lob, PDO::PARAM_LOB);
    $stmt->fetch(PDO::FETCH_BOUND);
    
    header("Content-Type: $type");
    fpassthru($lob);
    

    You'll probably need to cross-reference with the CodeIgniter documentation if the objects used in your code are part of that framework.

    If the returned resource is of type stream (as in the example code) then you might be able to just use stream_get_contents like so:

    $this->output->set_header('content-type: image/jpeg');
    echo stream_get_contents($row['PIC']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败