PHP:是否可以重用 MySQL pdo 对象?
我允许用户对内容进行投票,因此我需要将用户输入保存到数据库中,然后获取输入的 COUNT()
返回。
投票工作正常,但读回结果总是返回 false。我发现的唯一解决方法是再次重建数据库连接来计票。还有其他方法可以做到这一点吗?
这是我的代码:
$vote = $conn->prepare($voteSQL);
$vote->execute(array(':postId'=>$voteId
, ':voterId'=>$userId
, ':voteType'=> $voteDir
,':voteType2'=> $voteDir
,':voteType3'=> $voteDir));
$tallyVotes = $conn->prepare($tallySQL);
$tallyVotes->execute(array(':postId'=>$voteId));
$updatedTally = $tallyVotes->fetch();
I am allowing users to vote on content, so I need to save a user input to my database, and then get a COUNT()
of the input to return back.
The voting works fine, but reading the results back always returns false. The only work around I have found is to rebuild the database connection a second time to count the votes. Is there any other way to do this?
Here is my code:
$vote = $conn->prepare($voteSQL);
$vote->execute(array(':postId'=>$voteId
, ':voterId'=>$userId
, ':voteType'=> $voteDir
,':voteType2'=> $voteDir
,':voteType3'=> $voteDir));
$tallyVotes = $conn->prepare($tallySQL);
$tallyVotes->execute(array(':postId'=>$voteId));
$updatedTally = $tallyVotes->fetch();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论