如何在没有引号的CodeIgniter中添加空条件?

时间:2014-08-03 21:51:31

标签: mysql codeigniter quotes backticks

此代码:

$this->db->where('id_etablissement_commanditaire IS ', $_POST['id_etablissement_commanditaire'], FALSE  );

给出:

WHERE id_etablissement_commanditaire IS NULL

那一个:

$this->db->where('id_etablissement_commanditaire IS ', $_POST['id_etablissement_commanditaire']);

给出:

WHERE `id_etablissement_commanditaire` IS 'NULL'

有没有办法获得:

    WHERE `id_etablissement_commanditaire` IS NULL

即。我想要反叛但不是引用。

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

if ($_POST['id_etablissement_commanditaire']) {
    $this->db->where('id_etablissement_commanditaire IS ', $_POST['id_etablissement_commanditaire']);
} else {
    $this->db->where('id_etablissement_commanditaire IS NULL', null, false)
}