PHP PDO Pgsql boolean value

Viewed 21

I use php 7.4.2, pgsql 13.3, pdo_pgsql extension and strict types. And I have function where $this->db is PDO object:

public function setAdministratorFlag(int $userID, bool $administrator):void {
    $statement = $this->db->prepare("
        update users set
        administrator = :administrator
        where id = :id;
    ");

    $statement->execute([
        "id" => $userID,
        "administrator" => $administrator,
    ]);
}

Administrator column in database looks like:

administrator boolean not null default false

If argument $administrator = true everything works good but when $administrator = false I get an exception:

Invalid text representation: 7 ERROR: invalid input syntax for type boolean: ""

When I add this to the code it starts working fine:

$administrator = $administrator === false ? "false" : $administrator;

Is there an option to force PDO to treat false as false without conversion to string?

0 Answers
Related