This code fails to correctly grab my record that is already confirmed (a value of 1 in the confirmed column of my database = confirmed. 0 is not. This user I’m grabbing is indeed confirmed. The return it is returning in this function is the return array(true,“”);
public function activate($activationKey)
{
$findSub=$this->pdo->prepare("SELECT * FROM Subscribers WHERE activationKey=:activationKey");
$findSub->execute(array(":activationKey" => $activationKey));
$subDetails=$findSub->fetch(PDO::FETCH_ASSOC);
if($findSub->rowCount()>0)
{
if($subDetails["confirmed"]===1)
{
return array(false,"alreadyactivated");
}
else
{
$activateSub=$this->pdo->prepare("UPDATE Subscribers SET confirmed=1 WHERE activationKey=:activationKey");
$activateSub->execute(array(":activationKey" => $activationKey));
return array(true,"");
}
}
else
return array(false,"notfound");
}
Can anyone spot the issue? It’s something to do with this line here I think.
Ok I’m not going crazy, but boolean didn’t work, so I retried string, and it’s definitely being pulled as a string. The column is set as a TINYINT(4) right now. This is weird.
I wish I could make a decision as to what to do. I feel like casting is the right option, but I don’t feel either of us actually know the best course of action here .
For consistency, I want to keep === and not == but that requires casting, I feel.
Not sure how to implement that with my setup TBH. In all examples I could find, they have a placeholder :example where they set the bind param on the :example placeholder in PDO. I don’t do that.
string(1) “0” on the first load (correctly being 0.)
string(1) “1” on the second load (correctly being 1.)
Both strings though.
Can you at least confirm whether MySQL always returns results in varchar instead of the data type of the column (e.g. integer?)
Again, I’m not using a PDO placeholder like in that example. I don’t have hte equivalent :numMonths. I pull the result via a select that bases it off the activationKey. And I just happen to pull another column from that result. I am new to PDO so if that example is still transferable to my situation, I don’t see it.