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

share|improve this question

25% accept rate
feedback

2 Answers

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.

share|improve this answer
I am happy to treat it as a string; however, I need to know the function which allows me to retrieve the data from the DB. – LenB Jan 19 at 12:11
@LenB it already should be – Explosion Pills Jan 19 at 13:11
feedback

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

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.