开发者

PHP: Is it possible to reuse MySQL pdo objects?

开发者 https://www.devze.com 2023-02-28 11:01 出处:网络
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.

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 aro开发者_StackOverflowund 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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号