-1

试图迁移到 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 />';
4

1 回答 1

0

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

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

foreach ($rows as $row) {
  echo $row awscoreaw['awscoreaw_def'].' '.$row['awscoreaw'].'<br />';
}
于 2012-10-28T03:45:19.850 回答