2

我正在写这样的查询:-

$data = array(
    'company_billing' => "if (company_billing  = $userId, (NULL), $userId)",
    'company_admin' => "if (company_admin  = $userId, (NULL), $userId)",
);

$this->db->where('id', $organizationId);
$this->db->update('organization', $data);

我期待类似的东西:-

UPDATE `organization` SET `organization`.`company_billing` = if (company_billing = 2, (NULL), 2), `organization`.`company_admin` = if (company_admin = 2, (NULL), 2) WHERE `id` = 1

但我得到:-

UPDATE `organization` SET `organization`.`company_billing` = 'if (company_billing = 2, (NULL), 2)', `organization`.`company_admin` = 'if (company_admin = 2, (NULL), 2)' WHERE `id` = 1

如果条件块,我想跳过那些引号。

有什么方法可以实现这一点,否则我将不得不编写本机查询?

谢谢

4

1 回答 1

1

::update::insert函数值会自动转义,从而产生更安全的查询。

$this->db->set('company_billing' , "if (company_billing  = $userId, (NULL), $userId)", false);
$this->db->set('company_admin', "if (company_admin  = $userId, (NULL), $userId)", false);
$this->db->where('id', $organizationId);
$this->db->update('organization');
于 2012-03-21T18:56:49.943 回答