$res->execute();
while($result=$res->fetch(PDO::FETCH_ASSOC)){
echo $result['字段'];
}
输出 数组行 用 print_r(数组);
输出json
$v=array("h"=>"300" , "m"=>"280" , "l"=>"250");
$json=json_encode($v);
这个回答,大家都不能接受
$res->execute();
while($result=$res->fetch(PDO::FETCH_ASSOC)){
echo $result['字段'];
}
$res->execute();
while($result=$res->fetch(PDO::FETCH_ASSOC)){
echo $result['字段'];
}
第二次返回false我感觉是到达记录尾了,fetch会向下移动结果集指针,至于返回数组可以使用fetchall,fetchall会返回一个二维数组,之后再转换成json格式就行