we are working on HRM system where user profile pictures are displayed. We have a working Java version which take blob from db2 and after processing displays it. It works fine. Now we are trying to do the same stuff with php using pdo.
Here is the code we use to get the job done but it does not work.
BLOB is in format of
FFD8FFE000104A46494600010201012C012C0000FFE1129345786966000049492A000800000009000F01 ....
Code:
static function arr('SELECT * FROM TABLE WHERE ID_PERSON= 22') {
global $conn;
$n = count($conn->query($sql)->fetchAll());
if ($n > 0) { $q = $conn->query($sql);
if (!$q) {$rs = $conn->errorInfo();}
while ($row = $q->fetch(PDO::FETCH_ASSOC)) {$rs[]=$row;} }
else {$rs = 'empty';}
return $rs;
}
in page it is located as like this
<img src="data:image/jpeg;base64,<?=base64_encode(hex2bin($rs['IMAGE_COLUMN']))?>"
and it is view like this (almost similar like the java result but it is not and does not work).
src="data:image/jpeg;base64, /9j/4AAQSkZJRgABAgEBLAEsAAD/4RKTRXhpZgAASUkqAAgAAAAJAA8BAgAGAAAAegAAABABAgAWAAAAgAAAABIBAwABAAAAAQAAABoBBQABAAAAlgAAABsBBQABAAAAngAAACgBAwABAAAAAgAAADEBAgAbAAAApgAAADIBAgAHYCAACdggUAAQAAAH4CAAAiiAMAAQAAAAMAAAAniAMAAQAAAPQBAAAwiAMAAQAAAAIAAAAyiAQAAQAAAPQBAAAAkAcABAAAADAyMzADkAIAFAAAAIYCAAAEkAIAFAAAAJoCAAABkgoAAQAAAK4CA ....
We are might be wrong on hex2bin but it is taken advise from Stack Overflow and its result much more like the working one. and without it is is not looking like base64 at all.
BLOB
column, it's already binary data and there's no need forhex2bin()
. – mustaccio Aug 19 at 16:30