/** * Persists the given person to the database * * @param \Foodalizr\Model\Person $person * @return \Foodalizr\Model\Person */ public function save(Model\Person $person) { if (null === $person->getId()) { $query = 'INSERT INTO `person` (`name`) VALUES (:name);'; $stmt = $this->getDb()->prepare($query); } else { $query = 'UPDATE `person` SET `name` = :name WHERE `id` = :id;'; $stmt = $this->getDb()->prepare($query); $stmt->bindParam(':id', $person->getId(), \PDO::PARAM_INT); } $stmt->bindParam(':name', $person->getName(), \PDO::PARAM_STR); $this->executeStatement($stmt); if (1 != $stmt->rowCount()) { throw new \OutOfBoundsException(); } if (null == $person->getId()) { $person->setId($this->getDb()->lastInsertId()); } return $person; }