SQL OR Operator not working

Good day

I’m trying to add a friend request functionality but this statement can’t work .

public function cancel_or_ignore_friend_request($data){

 $this->db->query('DELETE FROM friend_request WHERE (sender = :my_id AND receiver = :frnd_id) OR (sender = :frnd_id AND      receiver = :my_id)');

 $this->db->bind(':my_id', $data['my_id']);

 $this->db->bind(':frnd_id', $data['user_id']);



 if($this->db->execute()){

   return true;

 }else {

   return false;

 }

}

it’s just not working, Here am trying to create ignor or cancel friend request.

Please help

Thanks in advance
if more code is needed please let me know

If you are using real prepared queries, you cannot bind the same place-holder more than once, you would be getting an error, but you have no error handling. If you are using emulated prepared queries, what you are doing will ‘function’, but you should turn off emulated prepared queries when you make the database connection.

Next, in most applications, data is almost never actually deleted. If you are ignoring a friend request, you don’t want that person to continue to make the request after you ignore it once. You should instead have a column in the table, named delete or ignore, and just UPDATE it from a zero to a one, then exclude rows that have had that column set to a one in most database operations.

Thanks @phdr
I will implement the ignoring functionality
Please check this link i asked this question in full details

Just noticed, you are apparently using the PDO extension (based on the place-holder syntax), however, none of the ->query(), ->bind() (doesn’t exist at all), or ->execute() calls match how PDO would be used with a prepared query.

With PDO, you would call the PDO ->prepare() method. This returns a PDOStatement object. You would then call bindParam()/bindValue() methods, then call the ->execute() method OR more simply just call the ->execute([…]) method with an array consisting of the input values.

What database extension are you using?

Am using sql server so its sql.
I renamed my place-holders and it works
Thank you.

Sponsor our Newsletter | Privacy Policy | Terms of Service