public function insertOrUpdate(GenericEntity $entity) { $entityID = $entity->{"get" . ucfirst($entity->getIdcolumn())}(); $preparedStatement = NULL; if ($entityID != NULL) { $updateStatement = "update " . $entity->getTablename() . " set " . $this->getEntityValuesAsCommaSeperatedUpdateString($entity) . " where " . $entity->getIdcolumn() . "='" . $entityID . "';"; $preparedStatement = $this->PDO->prepare($updateStatement); $preparedStatement->execute(); return 0; } else { $insertStatement = "insert into " . $entity->getTablename() . " (" . $this->getEntityColumnsAsCommaSeperatedString($entity) . ") values (" . $this->getEntityValuesAsCommaSeperatedString($entity) . ");"; $preparedStatement = $this->PDO->prepare($insertStatement); $preparedStatement->execute(); return $this->PDO->lastInsertId(); } }