代码点击器使用连接表删除数据 [英] Code igniter deleting data with joins tables

查看:200
本文介绍了代码点击器使用连接表删除数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SQL中,我们可以使用JOINS从表中删除数据,例如

Logically in SQL we can delete data from tables with JOINS e.g.

DELETE  clb_subscriber_group_mapping .* FROM clb_subscriber_group_mapping 
INNER JOIN clb_driver_group ON (clb_driver_group.id = clb_subscriber_group_mapping.driver_group_id)
INNER JOIN clb_company ON (clb_company.id = clb_driver_group.company_id)
WHERE clb_company.id = 256 AND clb_subscriber_group_mapping.subscriber_id = 1784;

上述查询的代码Igniter是什么?

What will be the Code Igniter equivalent of above query?

代码Igniter支持使用连接删除查询?

Does Code Igniter support Delete query with joins?

推荐答案

不能使用CodeIgniter的Active Record类。它不支持在删除查询中的联接。您必须使用Robin Castlin提到的 $ this-> db-> query()执行查询。

You can't do that with CodeIgniter's Active Record class. It doesn't support joins in delete query. You'll have to execute the query using $this->db->query() as mentioned by Robin Castlin.

下面的代码取自核心文件。它是内部组件之一,它生成 DELETE 查询。

The below code is taken from the core files. It is one of the inner components, that generates the DELETE query.

function _delete($table, $where = array(), $like = array(), $limit = FALSE)
{
    $conditions = '';

    if (count($where) > 0 OR count($like) > 0)
    {
        $conditions = "\nWHERE ";
        $conditions .= implode("\n", $this->ar_where);

        if (count($where) > 0 && count($like) > 0)
        {
            $conditions .= " AND ";
        }
        $conditions .= implode("\n", $like);
    }

    $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;

    return "DELETE FROM ".$table.$conditions.$limit;
}

正如你所看到的,没有什么指定插入 JOIN 子句。

As you can see, there's nothing in there that specifies the insertion of a JOIN clause.

这篇关于代码点击器使用连接表删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆