1

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();
Johan
  • 74,508
  • 24
  • 191
  • 319
Chris Sobolewski
  • 12,819
  • 12
  • 63
  • 96
  • check if you have transactions enabled by chance. – Ajoy Apr 25 '11 at 21:55
  • I am not explicitly using ::beginTransaction... how else would I check for this? – Chris Sobolewski Apr 25 '11 at 21:59
  • I'll admit, I'm having trouble following your question but by any chance are you trying to use PDO's `rowCount()` function? If so, there are problems with it detailed at http://stackoverflow.com/questions/883365/count-with-pdo – Farray Apr 25 '11 at 22:03
  • does the db get updated immediately after the vote->execute is called ? ( like if you exit the application right after and you look at the data using a mysql client ) – Ajoy Apr 25 '11 at 22:06

0 Answers0