Display image stored in blob with PDO? [duplicate]

0

I have stored an image using the BLOB field of MySQL ( LONGBLOB ), but I can not display it in html :

//Instanciando minha classe com PDO e fazendo um 
//SELECT de todos os dados da tabela, inclusive a imagem
<?php
   $DAO = new DAO();
   $result = $DAO->select("SELECT * FROM TB_ADVOGADOS ORDER BY DT_CREATED DESC", array());
?>
//O foreach da tabela com os dados e a imagem
<?php foreach ($result as $row) { 
   $createDate = new DateTime($row['DT_CREATED']); ?>
   <tr>
     <td><input type="checkbox" name="ckhbox" /></td>
     <td><?php echo $row['TXT_NAME']; ?></td>
     <td><?php echo $row['NM_AGE']; ?></td>
     <td><?php echo $row['TXT_DESCRIPTION'] ?></td>
     <td><?php echo $createDate->format('d-m-Y') ?></td>
     <td><?php echo $row['PIC_IMAGE'] ?></td>
   </tr>
<?php } ?>

I think I need to format my $row['PIC_IMAGE'] to something that recognizes this string BLOB and I found some examples with mysql_fetch_object , but none with PDO that I can use. Just to help in understanding, I'll leave below the form I used to store the image in the bank:

<?php 
   $imageTmp = $_FILES['image']['tmp_name'];
   $imageSize = $_FILES['image']['size'];
   $imageType = $_FILES['image']['type'];
   $imageName = $_FILES['image']['name'];

    if($imageTmp != "none"){
       $fileManager = fopen($imageTmp, "rb");
       $conteudo = fread($fileManager, $imageSize);
       $conteudo = addslashes($conteudo);
       fclose($fileManager);
    }
    $DAO = new DAO();
    $result = $DAO->query("INSERT INTO TB_ADVOGADOS (ID_USER, TXT_NAME, NM_AGE, 
    TXT_DESCRIPTION, PIC_IMAGE) VALUES (:ID, :NAME, :AGE, :DESCRIPTION, :IMAGE)", 
    array(":ID"=> $idUser, ":NAME"=> $name, ":AGE"=> $age, 
    ":DESCRIPTION"=> $description, ":IMAGE"=> $conteudo));

?>

Any tips on how I can display them?

EDIT:

Below is the content of my DAO class:

<?php 

class DAO extends PDO {

private $conn;

public function __construct(){
    $this->conn = new PDO("mysql:host=localhost;dbname=meu_banco","usuario","senha");
}

private function setParams($statement, $parameters = array()){
    foreach($parameters as $key => $value){ 
        $this->setParam($statement, $key, $value);
    }   
}

private function setParam($statement, $key, $value){
    $statement->bindParam($key, $value);
}

public function query($rawQuery, $params = array()){
    $stmt = $this->conn->prepare($rawQuery);
    $this->setParams($stmt, $params);
    $stmt->execute();
    return $stmt;
}

public function select($rawQuery, $params = array()){
    $stmt = $this->query($rawQuery, $params);
    return $stmt->fetchAll(PDO::FETCH_ASSOC);
}

}

?>
    
asked by anonymous 31.08.2017 / 22:29

0 answers