List DB data using echo (PDO)

0

Hello, I have this code:

<<?php 
include("conexao.php");
$pdo = conectar();

$buscarusuario = $pdo->prepare("SELECT * FROM tab_clientes WHERE ID=:id");
$buscarusuario->bindValue(":id",2,PDO::PARAM_INT);
$buscarusuario->execute();

$linha = $buscarusuario->fetchAll(PDO::FETCH_OBJ);
foreach ($linha as $listar) {
echo "E-mail: ".$listar->email."</br>";
var_dump($listar);
}

My problem is that echo does not appear on the screen, I tested it with var_dump and it shows the DB data. Using FETCH_ASSOC of normal, but since I'm learning PDO, I wanted to do this using FETCH_OBJ , too, but as I said, echo is not displayed on the screen. Does anyone have an idea why this occurs or what other way to display it? Thank you!

    
asked by anonymous 13.12.2017 / 23:34

2 answers

2

Try this out

 <?php 
    include("conexao.php");
    $pdo = conectar();

    $buscarusuario = $pdo->prepare("SELECT * FROM tab_clientes WHERE ID=:id");
    $buscarusuario->bindValue(":id",2,PDO::PARAM_INT);
    $buscarusuario->execute();

    while($listar = $buscarusuario->fetch(PDO::FETCH_OBJ)){
    echo "E-mail: ".$listar->email."</br>";
    var_dump($listar);
    }
    
14.12.2017 / 02:42
0

You have to handle the result if I'm not mistaken, play the variable that receives the result in an array and then foreach the array

    
14.12.2017 / 01:03