的index.php
require_once '../../konfig/conn.php';
echo $id = $_SESSION['id'];
$sql = "SELECT * FROM i_user WHERE id_login = $id";
$stmt = $conn->prepare($sql);
$stmt->execute() . "<br/>";
我尝试计算数据库中的数据并开始工作
echo "<br>".$stmt->rowCount()." Total Rows";
结果是&#34; 1总行数&#34;,请帮我解决这个问题......
while ($stmt->fetch(PDO::FETCH_LAZY)) {
echo $stmt->id_login;
echo $stmt->nama_depan;
}
return $stmt;
答案 0 :(得分:0)
您需要将获取结果分配给变量:
while($row = $stmt->fetch(PDO::FETCH_LAZY)){
echo $row->id_login;
echo $row->nama_depan;
}
答案 1 :(得分:-1)
也许是这样的?
while($rs = $stmt->fetch(PDO::FETCH_LAZY)){
echo $rs->id_login;
echo $rs->nama_depan;
}
或者,使用带有绑定变量的预准备语句
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;
}
}
}