<?php 



class DaoFaq extends conexao {

public function Atualizar(faq $faq) {

try {

if ($faq->getFaq_id() != '') {

$sql = " UPDATE faq SET
faq_pergunta = ?,
faq_resposta = ?
WHERE faq_id = ? ";

$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $faq->getFaq_pergunta());
$stmt->bindValue(2, $faq->getFaq_resposta());
$stmt->bindValue(3, $faq->getFaq_id());


} else {

$sql = " INSERT INTO faq (faq_pergunta,faq_resposta)
VALUES (?,?)";


$stmt = self::conectar()->prepare($sql);
$stmt->bindValue(1, $faq->getFaq_pergunta());
$stmt->bindValue(2, $faq->getFaq_resposta());


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

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

}

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

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



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

 
}
