我试图从fetchAll从MySQL获取某些数据。选择数组中的数据与PDO fetchAll
目前,我有这样的:
$sql1= $dbh->query("SELECT * FROM information");
$comments= $dbh->prepare("SELECT * FROM comments WHERE idinformation= ?");
if($retail){
while($row = $retail -> fetch(PDO::FETCH_ASSOC)){
$comments->execute(array($row['idproducts']));
$json['data'][] = array(
'id'=>$row['idproducts'],
"headline"=>$row['headline'],
'price'=> array ("full_price" => $row['full_price']),
'description'=>$row['description'],
"comments" => $comments->fetchAll(PDO::FETCH_ASSOC)
);
}
$json_encode = json_encode($json);
$obj = json_decode($json_encode,true);
}
我的意见是输出所有列在我的数据库。如果我只想要评论,时间,ID等等,我该怎么区分这个语法?
在此先感谢!
而不是“*”在查询中写入列名。 – itachi