【问题标题】:Codeigniter Delete ... Where ... andCodeigniter 删除 ... 在哪里 ... 和
【发布时间】:2015-11-26 17:45:03
【问题描述】:

我需要一点帮助。 如何使用 codeigniter 发送此查询?

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

我只发现:

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

谢谢大家!

【问题讨论】:

  • 它只是工作,但不是很好: $this->db->where("(whos = '$senderid' and who = '$friendid' OR who = '$senderid' and whos = ' $friendid')");
  • 文档应该告诉你这一点。:codeigniter.com/user_guide/database/…

标签: php sql codeigniter sql-delete


【解决方案1】:
$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->db->where('who', 5)->where('whos', 1)->or_where('whos', 5)->where('who', 1);
$this->db->delete('friendconnect');

这也是:

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

更多信息:here

【讨论】:

    【解决方案2】:

    就用这个$this->db->query("Delete FROM friendconnect WHERE who = 5 and whos = 1 OR whos = 5 and who = 1");

    【讨论】:

    • 也许这个查询不够安全?
    • 为了安全你可以使用存储过程。
    【解决方案3】:
    $this->db->where('(who = 5 and whos = 1) OR (whos = 5 and who = 1)');
    $this->db->delete('friendconnect');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-04
      • 2015-06-13
      • 2012-06-18
      • 2018-11-23
      • 1970-01-01
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      相关资源
      最近更新 更多