mysql - PHP: PDO Query returns no results, but the same query returns 4 results in phpmyadmin? -
i have written query return comments post, excluding blocked users post. have tested query in phpmyadmin , 4/5 possible comments given post (where 1 user 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 checkin_comments comments join entity ent on comments.entity_id = ent.entity_id left join friends f on ent.entity_id = :entityid comments.chk_id = :checkinid , f.category != 4 group comments.comment_id "; // bind parameters query $data = array(":checkinid" => (int)$checkinid, ":entityid" => (int)$userid);
if run query on phpmyadmin values 1726
checkinid , 1517
userid expected outcome, in php 0 results. used var_dump print contents of data , shows as:
array(2) { [":checkinid"]=> int(1726) [":entityid"]=> int(1517) }
why experiencing different results in php? other queries run fine
edit if swap bind variables number values query works fine, leads me believe problem pdo binding values query. when perform bind use pdo wrapper class executes 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 scream answer more experienced users of pdo?
i think not including params in single quotes. try code
$query = "select `ent`.`entity_id`, `ent`.`profile_pic_url`, `ent`.`first_name`, `ent`.`last_name`, `ent`.`last_checkin_place`, `comments`.`content` `checkin_comments` `comments` join `entity` `ent` on `comments`.`entity_id` = `ent`.`entity_id` left join `friends` `f` on `ent`.`entity_id` = ':entityid' `comments`.`chk_id` = ':checkinid' , `f`.`category` != 4 group `comments`.`comment_id` "; // bind parameters query $data = array(":checkinid" => (int)$checkinid, ":entityid" => (int)$userid);
i hope help.
Comments
Post a Comment