Husni AL-Fikri Dalimunthe Husni AL-Fikri Dalimunthe - 1 month ago 9
PHP Question

Undefined property: PDOStatement::,$id_login,$nama_depan

Index.php

Include '../../konfig/conn.php';
echo $id=$_SESSION['id'];

$sql="SELECT*FROM i_user WHERE id_login=$id";
$stmt=$conn->prepare($sql);
$stmt->execute()."<br>";


I'm Try to count data from database and it's working

echo "<br>".$stmt->rowCount()." Total Rows";


and the result is "1 Total Rows", Please help me to fixed this...

while($stmt->fetch(PDO::FETCH_LAZY)){
echo $stmt->id_login;
echo $stmt->nama_depan;
}
return $stmt;


and this picture
from my database php code

Answer

Perhaps like this?

while($rs = $stmt->fetch(PDO::FETCH_LAZY)){
    echo $rs->id_login;
    echo $rs->nama_depan;
}

Or, using prepared statement with a bound variable

include '../../konfig/conn.php';
$id=$_SESSION['id'];

$sql="SELECT * FROM i_user WHERE id_login=:id";

$stmt=$conn->prepare( $sql );
if( $stmt ){
    $stmt->bindParam(':id',$id);
    $res = $stmt->execute();
    if( $res ){
        while( $rs=$stmt->fetch( PDO::FETCH_LAZY ) ){
            echo $rs->id_login, $rs->nama_depan;
        }
    }
}