PDO 新手...我正在尝试求和,但这里出现错误是我的代码
function test_score_month($student_id){
global $host, $dbname, $user, $pass;
$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
$STH = $DBH->query("SELECT SUM(score), SUM(score_from) FROM school_test_report
WHERE
school_test_report.test_date >= last_march() and school_test_report.test_date <= march()" );
$STH->setFetchMode(PDO::FETCH_BOTH);
return $STH;
}
输出是
$student_id = test_score_month($name);
echo $student_id['SUM(score)'];
但出现错误
Call to a member function setFetchMode() on a non-object in
我试过了
$STH->setFetchMode(PDO::FETCH_ASSOC);
但仍然是同样的错误