Search code examples
phpmysqlsqlmedoo

I can't add OR operator inside my sql query


My code look like this:

$database->update($campaign_table, $data_nga_posti , array("AND" => ["codice_pod" => $data_nga_posti['codice_pod'],("codice_pdr" =>NULL) ]));

So this is when my query execute:

UPDATE `field` SET `columnname` = 'data',`anothercm` = 'data',WHERE `codice_pod` = 'IT001E35563561' AND `codice_pdr` IS NULL

I want to my query look like this.

UPDATE `field` SET `columnname` = 'data',`anothercm` = 'data',WHERE `codice_pod` = 'IT001E35563561' AND (`codice_pdr` IS NULL OR `codice_pdr` ="")

but I dont know how to put OR(operator ) inside this code.


Solution

  • I have never used this before, and have nothing to test with but the closted example posted in the documentation is:

    $database->has("account", [
        "AND" => [
            "OR" => [
                "user_name" => "foo",
                "email" => "[email protected]"
            ],
            "password" => "12345"
        ]
    ]);
    

    So I think this would work for you:

    $database->update($campaign_table, $data_nga_posti, [
        "AND" => [
            OR => [
                "codice_pdr" =>NULL, 
                "codice_pdr" => ""
            ],
            "codice_pod" => $data_nga_posti['codice_pod']
        ]
    ]);