Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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.

share|improve this question
    
If it's really a BLOB column, it's already binary data and there's no need for hex2bin(). – mustaccio Aug 19 at 16:30
    
we tried without hex2bin. But this approach does not bring any close wanted result – ISkandar Aug 20 at 4:47

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.