<?php

class DaoNewsletter extends conexao {

public function Atualizar(newsletter $newsletter) {

try {

if ($newsletter->getNewsletter_id() != '') {

$sql = " UPDATE newsletter SET
newsletter_email = ?

WHERE newsletter_id = ? ";

$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $newsletter->getNewsletter_email());
$stmt->bindValue(2, $newsletter->getNewsletter_id());


} else {

$sql = " INSERT INTO newsletter (newsletter_email)
VALUES (?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $newsletter->getNewsletter_email());



}
if ($stmt->execute()){
return true;
} else
return false;

} catch (Exception $e) {
print "Erro ao tentar atualizar: ".$e;
}

}

public function Pesquisarnewsletter($codigo){
$sql = " SELECT * FROM newsletter WHERE newsletter_id = ? ";
$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $codigo);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

public function Listarnewsletter(){
$sql = " SELECT * FROM newsletter ORDER BY newsletter_id ";
$stmt = self::conectar()->prepare($sql);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $result;
}

	public function deletar($newsletter_id){		
		$sql = " DELETE FROM newsletter WHERE newsletter_id = ? ";
		$stmt = self::conectar()->prepare($sql);
		$stmt->bindValue(1, $newsletter_id); 
		$stmt->execute();
	}

}

?>
