赞
踩
如果在phpmyadmin中输入,则以下查询将返回所有想要的结果:
SELECT postid, voting
FROM postvotes
WHERE userid = 1
AND postid IN
(1007,1011,1012,1013,1014,
1015,1016,1017,1018,1019,1020,1021,1023,1025,1026,
1027,1028,1029,1030,1031)
但PDO无法fetchAll() . 它只返回第一个匹配,如fetch() .
怎么了?
PHP代码:
private function userPostVotings( $postIDs ) {
// $postIDs contains a string like 1,2,3,4,5,6,7...
// generated through implode(',', idArray)
try {
$userPostVote = $this->_db->prepare('SELECT postid, voting
FROM postvotes
WHERE userid = ?
AND postid IN ( ? )');
$userPostVote->setFetchMode(\PDO::FETCH_ASSOC);
$userPostVote->execute( array( $this->_requester['id'], $postIDs ) );
while ( $res = $userPostVote->fetch() ) {
var_dump( $res );
}
} catch (\PDOException $p) {}
}
如果我回显出此方法中使用的查询并通过phpmyadmin触发它,我会得到正确数量的结果 . 然而,PDO只给出了第一个 . 无论是带有fetch()还是fetchAll()的循环 .
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。