Arquivado
Este tópico foi arquivado e está fechado para novas respostas.
- 0

Erro não detectado: Chame para uma função de membro rowCount () em booleano
Perguntado por
pedrook16
Este tópico foi arquivado e está fechado para novas respostas.
Perguntado por
pedrook16
Ao usar o fórum, você concorda com nossos Termos e condições.
<?php
class Contato {
private $pdo;
public function __construct() {
$this->pdo = new PDO("mysql:dbname:crudoo;host:localhost", "root", "");
}
public function adicionar($email , $nome = '') {
if ($this->existeEmail($email) == false) {
$sql = "INSERT INTO contatos ( nome , email) VALUES (:nome, :email)";
$sql = $this->pdo->prepare($sql);
$sql->bindValue(':nome', $nome);
$sql->bindValue(':email', $email);
$sql->execute();
return true;
}else{
return false;
}
}
public function getNome($email){
$sql = "SELECT nome FROM contatos WHERE email = :email";
$sql = $this->pdo->prepare($sql);
$sql->bindValue(':email', $email);
$sql->execute();
if ($sql->rouCount() > 0) {
$info = $sql->fetch();
return $info['nome'];
}else {
return '';
}
}
public function getAll(){
$sql ="SELECT * FROM contatos";
$sql = $this->pdo->query($sql);
if ($sql->rowCount() > 0) {
return $sql->fetchAll();
}else {
return array();
}
}
public function editar($nome, $email){
if ($this->existeEmail($email)) {
$sql = "UPDATE contatos SET nome = :nome WHERE email = :email";
$sql = $this->pdo->prepare($sql);
$sql->bindValue(':nome', $nome);
$sql->bindValue(':email', $email);
$sql->execute();
return true;
}else{
return false;
}
}
public function excluir($email){
if ($this->existeEmail($email)) {
$sql = "DELETE FROM contatos WHERE email = :email";
$sql = $this->pdo->prepare($sql);
$sql->bindValue(':email', $email);
$sql->execute();
return true;
}else{
return false;
}
}
private function existeEmail($email){
$sql = "SELECT * FROM contatos WHERE email = :email";
$sql = $this->pdo->prepare($sql);
$sql->bindValue(':email', $email);
$sql->execute();
if ($sql->rowCount() > 0 ) {
return true;
}else{
return false;
}
}
}
?>
Compartilhar este post
Link para o post
Compartilhar em outros sites