这是我的代码:
$money = $db_con
->prepare(" SELECT SUM(asker_amount) asker, SUM(responder_amount) responder
FROM money WHERE post_id = ? AND author_id = ? AND paid IS NULL")
->execute(array($ques_id, $author_ques_id))
->fetch(PDO::FETCH_ASSOC);
$asker_amount = $money['asker'];
$responder_amount = $money['responder'];
它不会执行并抛出此错误:
致命错误:在第5行
->fetch( ...
){file path}的布尔值上调用成员函数fetch()
好的,怎么了?我该如何解决?
注意:该查询也可以,我已经在phpmyadmin中对其进行了测试。
答案 0 :(得分:3)
试试这个。
$query = $db_con->prepare(" SELECT SUM(asker_amount) asker, SUM(responder_amount) responder
FROM money WHERE post_id = ? AND author_id = ? AND paid IS NULL");
$query->execute(array($ques_id, $author_ques_id));
$money = $query->fetch(PDO::FETCH_ASSOC);
$asker_amount = $money['asker'];
$responder_amount = $money['responder'];
您应该仅为$money
分配fetch
的结果。