Loop though them and remove the fields that are NULL before execution:
$fields = array(id=>3, name=>NULL, phone=>555-5555) $attrinutes = array(); foreach ($fields as $field => $value) { if(isset($value)){ $attributes[$field] = $value; } } $keys = array_keys($attributes); $values = array_values($attributes); $sql = "INSERT INTO ". static::$table_name ."("; $sql .= implode(", ", $keys ); $sql .= ") VALUES ("; $sql .= implode( ", ", array_fill(0, count($attributes) ,'?' ) ); $sql .= ")"; $q = $this->connection->prepare($sql); $q->execute($values); *** NOT TESTED ***
Also make sure the fields are set to NULL in your DB