示例#1
0
 public function persist()
 {
     $conexion = BD::getConexion();
     if ($this->getId() !== null) {
         $query = "update usuario SET nombre = :user, pass = :pass, email = :email, id_pintor = :pintor WHERE id_user = :id_usuario";
         $update = $conexion->prepare($query);
         try {
             $checkProcess = $update->execute(array(":user" => $this->getnombre(), ":pass" => $this->getPass(), ":email" => $this->getEmail(), ":pintor" => $this->getPintor(), "id_usuario" => $this->getId()));
         } catch (Exception $ex) {
             $checkProcess = null;
         }
         if ($checkProcess) {
             $pintor = $this->getPintor();
             $this->setPintor(Pintor::getPintor($pintor));
         }
     } else {
         $insert = "Insert into usuario (nombre,pass,email,id_pintor) values (:user, :pass, :email, :pintor)";
         $insercion = $conexion->prepare($insert);
         try {
             $checkProcess = $insercion->execute(array(":user" => $this->getnombre(), ":pass" => $this->getPass(), ":email" => $this->getEmail(), ":pintor" => $this->getPintor()));
         } catch (Exception $ex) {
             $checkProcess = null;
         }
         if ($checkProcess) {
             $this->setId($conexion->lastInsertId());
             $pintor = $this->getPintor();
             $this->setPintor(Pintor::getPintor($pintor));
         }
     }
     return $checkProcess;
 }