2
votes

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); 
    ....
}

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.

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

2

2 Answers

0
votes

Not all PDO drivers return a LOB as a file stream; mysql 5 is one example. You can try treating lob as a string after the bind.

0
votes

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