本文介绍了使用php PDO从mysql读取BLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有BLOB字段的数据库(weeklyOccupancy).我正在尝试使用以下方式在PHP中访问数据:

I have a database with a BLOB field (weeklyOccupancy). I am trying to access the data in PHP using:

$sqlCmd = 'select weeklyOccupancy from Occupancy order by startDate;';
$pdoStmt = $dbh->query($sqlCmd);
$pdoStmt->bindColumn(1, $lob, PDO::PARAM_LOB);
$pdoStmt->fetch(PDO::FETCH_BOUND);
foreach($pdoStmt as $row){
    $weeklyData = stream_get_contents($lob);
    ....
}

但是,stream_get_contents表示$ lob是一个字符串(名为资源ID#1"),尽管我认为它应该是一个流.我已经将其视为一个错误(http://www.php.net/manual /en/pdo.lobs.php#96311),但解决方法与我的应用程序无关-在其中,blob包含一个位字符串,而不是要显示的图像.

However, stream_get_contents says that $lob is a string (named "Resource id #1) although I believe it should be a stream. I have seen this mentioned as a bug (http://www.php.net/manual/en/pdo.lobs.php#96311) but the workaround is not relevant for my application - in which the blob holds a bit string not an image to be displayed.

有什么想法可以从PHP的blob字段中获取数据吗?谢谢

Any ideas how I can get the data out of a blob field in PHP? Thanks

推荐答案

糟糕.我的代码中有一个更早的错误.问题消失了.

Oops. There was an earlier error in my code. Problem gone.

这篇关于使用php PDO从mysql读取BLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 06:52