PDO Selection in the database mysql parameter BLOB

2

I'm having trouble trying to retrieve one or a list of images that I've already inserted into mysql 5 with PDO. I have a class of what has the architecture of my querys to work with the database.

class ImagemDao {

public function inserirImagem(ImagemEntity $imagem) {
    $conexao = ...
    $stmt = $conexao->getStance()->prepare("INSERT INTO imagem(imagem,id_pagina) VALUES(:img, :idPagina)");
    $stmt->bindValue(":img", $imagem->getImagem());
    $stmt->bindValue(":idPagina", $imagem->getIdPagina());
    $stmt->execute();

}
public function selecionaTodasImagens() {
    $conexao = ...
    $consulta = $conexao->getStance()->query("SELECT id_imagem, imagem, id_pagina FROM imagem;");
    while ($linha = $consulta->fetch(PDO::FETCH_OBJ)){

        echo $linha->id_imagem ."</br>" ;
        echo $linha->imagem ."</br>";
        echo $linha->id_pagina ."</br>";

    }
}

My bean is as follows.

class ImagemEntity {
private $id;
private $imagem;
private $idPagina;
function __construct($id = "", $imagem = "", $idPagina = "") {
    $this->id = $id;
    $this->imagem = $imagem;
    $this->idPagina = $idPagina;
}
 //get and set

and I have a test file

<?php 
    $dao = new ImagemDao();
    $dao->selecionaTodasImagens();

?>

What it returns to me are just the text of the image and its id but no display.

My bank entity is as follows.

in the browser is showing as follows.

    
asked by anonymous 21.04.2015 / 23:18

1 answer

2

See PDO - Large Objects (LOBs) .

Basically, you did not pass% constant at the time of binding ...

$stmt->bindValue(":img", $imagem->getImagem(), PDO::PARAM_LOB);

Of course I'm assuming that PDO::PARAM_LOB was previously initialized with a file or something of the sort (if you just pass the image name nothing will happen).

    
21.04.2015 / 23:41