public function update(UserModel $user) { $sql = 'UPDATE user SET email=:email, username=:username, password=:password, firstname=:firstname, lastname=:lastname, birthdate=:birthdate, isActive=:isActive WHERE id=:id '; $this->getDb()->beginTransaction(); try { $stmt = $this->getDb()->prepare($sql); $stmt->execute(array('email' => $user->getEmail(), 'username' => $user->getUsername(), 'password' => $user->getPassword(), 'firstname' => $user->getFirstname(), 'lastname' => $user->getLastname(), 'birthdate' => $user->getBirthdate()->format('Y-m-d'), 'isActive' => $user->getIsActive(), 'id' => (int) $user->getId())); $this->getDb()->commit(); } catch (PDOException $e) { $this->getDb()->rollBack(); throw $e; } }
public function insert(UserModel $user) { $sql = 'INSERT INTO user VALUES (' . 'NULL, ' . "'" . $user->getEmail() . "'," . "'" . $user->getUsername() . "'," . "'" . $user->getPassword() . "'," . "'" . $user->getFirstname() . "'," . "'" . $user->getLastname() . "'," . "'" . $user->getBirthdate()->format('Y-m-d') . "'," . "'" . (int) $user->getIsActive() . "'" . ")"; echo $sql; $this->getDb()->exec($sql); }