此条目与多个表(在下面的代码中标记为“ c”)相关,该表是参考表,不应删除。
我尝试这样做,但是失败了。我是否有一个简单的语法错误,或者在codeigniter中是不可能的,还是我已经用其他方式做到了?
$this->db->where(" (a.refid='".$this->session->ud('id')."' and b.refid='".$this->session->ud('id')."') and c.type='".$tempid."' and c.templateid=a.templateid and c.slug=b.slug");
$this->db->delete('a.*,b.*');
$this->db->from('table_a a, table_b b, table_c c');
$delinfo=$this->db->affected_rows();
另外,我解释了我想做什么。 我要删除 表a-该行具有“ refid”,并通过“ type”与表格c联系 表b-具有“ refid”的行,并通过“ slug”与表c联系 表c-没有要删除的内容
希望我能解释一下我要做什么,并感谢您的支持
答案 0 :(得分:1)
这里需要的是将删除与联接结合在一起-Codeigniters QueryBuilder不支持带有联接的delete语句-因此您必须编写自己的联接
类似以下的东西应该起作用
$this->db->query('
DELETE a,b,c FROM table_a a
JOIN table_c c ON (a.templatedid = c.templateid)
JOIN table_b b ON (c.slug = b.slug)
WHERE a.refid = ? AND c.type = ? AND b.refid = ?',
array($this->session->ud('id'), $tempid, $this->session->ud('id'))
);