I have written a query to return all comments for a post, excluding blocked users from that post. I have tested the query in phpmyadmin and I get 4/5 possible comments back for the given post (where 1 user is blocked).
The query looks like:
$query = "SELECT ent.Entity_Id, ent.Profile_Pic_Url, ent.First_Name, ent.Last_Name, ent.Last_CheckIn_Place, comments.Content
FROM checkin_comments AS comments
JOIN entity AS ent
ON comments.Entity_Id = ent.Entity_Id
LEFT JOIN friends AS f
ON ent.Entity_Id = :entityId
WHERE comments.Chk_Id = :checkInId
AND f.Category != 4
GROUP BY comments.Comment_Id
";
// Bind the parameters to the query
$data = Array(":checkInId" => (int)$checkInId, ":entityId" => (int)$userId);
If I run the query on phpmyadmin with the values 1726 for checkinId and 1517 for userId I get the expected outcome, however in PHP I get 0 results. I used var_dump to print the contents of data and it shows as:
array(2) {
[":checkInId"]=>
int(1726)
[":entityId"]=>
int(1517)
}
Why am I experiencing different results in PHP? All my other queries run fine
EDIT If I swap the bind variables for number values the query works fine, which leads me to believe this is a problem with PDO binding the values to the query. When I perform the bind I use my PDO wrapper class which executes the following methods:
public function fetchAll($query, $data = null)
{
$stmt = $this->prepareQuery($query, $data);
return $stmt->fetchAll();
}
private function prepareQuery($query, $data = null)
{
$stmt = $this->connection->prepare($query);
$stmt->execute($data);
return $stmt;
}
Does this scream the answer to any more experienced users of PDO?