0

This code:

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

Gives:

WHERE id_etablissement_commanditaire IS NULL

That one:

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

Gives:

WHERE `id_etablissement_commanditaire` IS 'NULL'

Is there a way to get :

    WHERE `id_etablissement_commanditaire` IS NULL

I.e. I would like backticks but not quotes.

halfer
  • 19,824
  • 17
  • 99
  • 186
Nils BAY
  • 35
  • 1
  • 7
  • I'm not sure you actually need backticks for that column name, so the first method should be fine as it is. http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks – shree.pat18 Aug 03 '14 at 21:54
  • you are right, it's not necessary, it was to get stuck to MySQL syntax. – Nils BAY Aug 04 '14 at 11:51

1 Answers1

0

Try something like this:

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)
}
Walid Ammar
  • 4,038
  • 3
  • 25
  • 48
  • Thanks, very good ! I have a question on your code at http://stackoverflow.com/questions/25118132/what-does-mean-if-postid-etablissement-commanditaire – Nils BAY Aug 04 '14 at 11:57
  • @NilsBAY you're welcome, the link you mentioned is broken, if this answer worked for your question please accept it. – Walid Ammar Aug 04 '14 at 12:57
  • 1
    @Nils, if your question is relating to this answer and is a small supplementary, just ask it here. I believe the new question was deleted by a moderator because you addressed it to Mohammed - we don't do that here - it just confused/confuses people. – halfer Aug 04 '14 at 13:41
  • Ok halfer. I would like to know if if ($_POST['id_etablissement_commanditaire']) is the same as if ($_POST['id_etablissement_commanditaire'] != '') ? or not ? – Nils BAY Aug 04 '14 at 22:42
  • @NilsBAY it involves that case, but also all of false values whose (`null`, `0`, `empty string("" or '')`, `not set`, `false`). – Walid Ammar Aug 05 '14 at 13:47