I have a class called clients. I have 2 methods called verificaCPF()
and queryInsert()
.
Both methods when doing the statement it is a return
(it is working normal). My question is whether this form I am doing is good practice? Do you do that?
Can you give me a hint to improve this part of the instruction return?
Thank you very much;)
public function verificaCPF($cpf) {
try {
$this->cpf = $cpf;
$stmt = $this->conn->conexao()->prepare("SELECT cli_cpf FROM clientes WHERE cli_cpf =:cli_cpf");
$stmt->bindParam(":cli_cpf", $this->cpf);
$stmt->execute();
if($stmt->rowCount() <=0){
return 'ok'; //ALGUMA DICA PRA SER MAIS LEGIVEL PRA QUEM TA DE FORA?
}else{
return 'nao';
}
} catch (Exception $ex) {
echo $ex->getMessage();
}
index.php
if (isset($_POST['cadCliente'])) {
$objCli = new clientes();
if($objCli->verificaCPF($_POST['cpf']) =='nao'){
echo '<script>alert("CPF EM DUPLICIDADE");</script>';
}else{
if ($objCli->queryInsert($_POST) == 'ok') {
echo '<script>alert("Cadastro realizado!");</script>';
}
}