I am using PDO for a dynamical update query for PostgreSQL. The problem is, all the values are transmitted to the database as strings, which throws an error for the supposed boolean (**edit**: and integer) values:

> 
> PHP Fatal error: Uncaught PDOException: SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type boolean: Â»Â«
> 
> 
> 

**Edit:** The problem appears whenever the boolean or integer fields get an empty input. What can I do to make the PDO transfer the inputs as "null" to the database instead of empty strings that throw the data type errors?

Below is my update method, I have tried to do the binding inside a loop and add an explicit type casting for the two supposed boolean values:

```
public function updateMod($array)
{
    $keys = array_keys($array);
    $vals = array_values($array);

    $setStr = "";
    foreach ($keys as $key) {
        $setStr .= "$key = :$key, ";
    }
    $setStr = rtrim($setStr, ", ");

    $pdoConn = DbConnection::openConnection();
    $stmt = $pdoConn->prepare("UPDATE mods SET $setStr WHERE id = :id;");

    $i = 0;
    foreach ($keys as $key) {
        // type casting the two supposed booleans:
        if($key === 'g_exists' || $key === 'w_exists') {
            $stmt->bindValue($key, $vals[$i], PDO::PARAM_BOOL);
        } else {
            $stmt->bindValue($key, $vals[$i]);
        }
        $i++;
    }

    $stmt->bindValue('id', $this->Id());

    if ($stmt->execute()) {
        return true;
    } else {
        return false;
    }
}

```

But I keep getting the same error.
Does anyone have an idea how to solve this?