php - What is wrong with this MySQL query. It gives invalid parameter number error -
mysql gives error:
sqlstate[hy093]: invalid parameter number
for query:
public function getuserfriends($userid) { $query = "select users.id, users.firstname, users.lastname, users.thumbpic friendships left join users on ((friendships.user1 = users.id or friendships.user2 = users.id) , users.id <> :userid) (user1 = :userid or user2 = :userid) , friendships.status = 1"; return $this->adapter->prepare($query)->execute(array(':userid' => $userid))->fetchall(); }
parameter number looks ok me or missing something?
unfortunately can't use same named parameter twice. have accomplish goal way: (i know... lame, right?)
public function getuserfriends($userid) { $query = " select users.id, users.firstname, users.lastname, users.thumbpic friendships left join users on (friendships.user1 = users.id or friendships.user2 = users.id) , users.id <> :userida (user1 = :useridb or user2 = :useridc) , friendships.status = 1"; return $this->adapter->prepare($query)->execute(array( ':userida' => $userid ':useridb' => $userid ':useridc' => $userid ))->fetchall(); }
Comments
Post a Comment