PHP Pdo帮助...无法让pdo fetchall为我工作

时间:2012-10-28 03:35:35

标签: php mysql pdo

尝试迁移到php pdo ...有人可以告诉我为什么地球上这段代码不起作用?

$stmt = $db->prepare("SELECT SUM(aw_score) AS awscoreaw, SUM(hm_score) AS awscoreaw_def FROM nfl_new WHERE away=:away AND date<:date AND Season=:season");

$stmt->bindValue(':away', $row['away'], PDO::PARAM_STR);
$stmt->bindValue(':date', $row['date'], PDO::PARAM_STR);
$stmt->bindValue(':season', $row['Season'], PDO::PARAM_STR);                            
$stmt->execute();
$affected_rows = $stmt->rowCount();
echo $affected_rows.' ';
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo $rows['awscoreaw_def'].' '.$row['away'].'<br />';

1 个答案:

答案 0 :(得分:0)

away不在您的选择列表中,并且您使用fetchAll,您需要迭代结果。

$rows = $stmt->fectchAll(PDO::FETCH_ASSOC);

foreach ($rows as $row) {
  echo $row awscoreaw['awscoreaw_def'].' '.$row['awscoreaw'].'<br />';
}