1

I need a little help. How can i send this query with codeigniter?

Delete FROM friendconnect WHERE who = 5 and whos = 1 OR whos = 5 and who = 1;

I found only that:

$this->db->where('id', $id);
$this->db->delete('mytable'); 

Thanks everybody!

2
  • it just works but not nice: $this->db->where("(whos = '$senderid' and who = '$friendid' OR who = '$senderid' and whos = '$friendid')"); Commented Sep 1, 2015 at 13:12
  • the documentation should tell you this.: codeigniter.com/user_guide/database/… Commented Sep 1, 2015 at 13:13

3 Answers 3

6
$this->db->where('who', 5);
$this->db->where('whos', 1);
$this->db->or_where('whos', 5);
$this->db->where('who', 1);

$this->db->delete('friendconnect');

This is also an alternative:

$this->db->where('who', 5)->where('whos', 1)->or_where('whos', 5)->where('who', 1);
$this->db->delete('friendconnect');

This also:

$this->db->where(array('who'=>5, array('whos'=>1)))->or_where('whos', 5)->where('who', 1);
$this->db->delete('friendconnect');

More info: here

Sign up to request clarification or add additional context in comments.

Comments

-1

Just use this $this->db->query("Delete FROM friendconnect WHERE who = 5 and whos = 1 OR whos = 5 and who = 1");

2 Comments

Maybe this query its not enough safety?
For safety you can use stored procedure.
-1
$this->db->where('(who = 5 and whos = 1) OR (whos = 5 and who = 1)');
$this->db->delete('friendconnect');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.