【问题标题】:How can I receive bytea data from PostgreSQL through Zend_Db_Select?如何通过 Zend_Db_Select 从 PostgreSQL 接收 bytea 数据?
【发布时间】:2012-03-02 10:57:41
【问题描述】:

我用 Zend Framework + Postgres 写了一个网站。在 PostgreSQL 中有这张表:

create table images(
    id                      serial,
    title                   TEXT DEFAULT '',
    thumbnail               bytea NOT NULL,
    original                bytea NOT NULL,
    PRIMARY KEY(id)
);

我打算在哪里存储图像数据。 但是当我尝试从桌子上接收任何东西时(select thumbnail from images where id = $id):

$table = $mapper->getDbTable();
$select = $table->select();
$select->from($table,array('thumbnail'));
$select->where('id = ?',$id);

$res = $table->fetchRow($select);
die(print_r($res['thumbnail']));

我收到类似的东西:

Resource id #12_

但不是包含数据。

我如何(使用Zend_Db_Select)接收这些数据,而不是资源ID #129? 对不起我的英语不好...

【问题讨论】:

  • 没有。资源 id 总是不同于记录的 id

标签: zend-framework postgresql zend-db-select


【解决方案1】:

如果问题仍然存在,请替换此行:

die(print_r($res['thumbnail']));

通过这个:

die(fpassthru($res['thumbnail']))

【讨论】:

    【解决方案2】:
    $stream = $res['thumbnail'];
    @unlink($pathFile);
    touch($pathFile);
    while (($buffer = (fgets($stream, 8192))) !== false) {
        file_put_contents($pathFile, $buffer, FILE_APPEND);
    }
    

    【讨论】:

    • 欢迎来到 Stack Overflow!不要只发布一段代码,请解释为什么这段代码可以解决所提出的问题。没有解释,这不是答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-29
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    • 2013-12-14
    相关资源
    最近更新 更多