尝试迁移到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 />';
答案 0 :(得分:0)
away
不在您的选择列表中,并且您使用fetchAll
,您需要迭代结果。
$rows = $stmt->fectchAll(PDO::FETCH_ASSOC);
foreach ($rows as $row) {
echo $row awscoreaw['awscoreaw_def'].' '.$row['awscoreaw'].'<br />';
}