getPdo(); $sql = "UPDATE `".$this->table."` SET "; $first = true; $values = []; foreach (get_object_vars($obj) as $key => $value) { if(in_array($key, ["id", "created_at"])) { continue; } if(!$first) { $sql .= ", "; } $first = false; $sql .= "`".$key."` = :".$key; if(is_bool($value)) { $value = (int)$value; } $values[":".$key] = $value; } $sql .= " WHERE `id` = ".$obj->id; $sth = $pdo->prepare($sql); $sth->execute($values); return true; } }