<?php 



class DaoServicos extends conexao {

public function Atualizar(servicos $servicos) {

try {

if ($servicos->getSer_id() != '') {

$sql = " UPDATE servicos SET
ser_titulo = ?,
ser_descricao = ?,
ser_imagem = ?
WHERE ser_id = ? ";

$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $servicos->getSer_titulo());
$stmt->bindValue(2, $servicos->getSer_descricao());
$stmt->bindValue(3, $servicos->getSer_imagem());
$stmt->bindValue(4, $servicos->getSer_id());


} else {

$sql = " INSERT INTO servicos (ser_titulo,ser_descricao,ser_imagem)
VALUES (?,?,?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $servicos->getSer_titulo());
$stmt->bindValue(2, $servicos->getSer_descricao());
$stmt->bindValue(3, $servicos->getSer_imagem());


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

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

}

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


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

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


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

 
}
