1

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 Answers 2

-1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.