-1
They taught me this: But it doesn’t work for me says Error: Call to a Member Function prepare() on null in D: wamp www New folder user classes.php on line 29.
<?php
Class usuarios
{
private $pdo;
public $msgErro = "";
public function conectar($nome, $host, $email, $senha)
{
global $pdo;
try
{
$pdo = new PDO("mysql:dbname=".$nome.";host".$host,);
} catch (PDOException $e) {
$msgErro = $e->getMessage();
}
}
public function cadastrar($nome, $telefone, $email, $senha)
{
global $pdo;
$sql = $pdo->prepare("SELECT id_usuarios FROM usuarios WHERE email = :e");
$sql->bindValue(":e",$email);
$sql->execute();
if($sql->rowCount() > 0)
{
return false;
}
else
{
$sql = $pdo->prepare("INSERT INTO usuarios (nome, telefone, email, senha) VALUES (:n, :t, :e, :s)");
$sql->bindValue(":n",$nome);
$sql->bindValue(":t",$telefone);
$sql->bindValue(":e",$email);
$sql->bindValue(":s",md5($senha));
$sql->execute();
return true;
}
}
public function logar($email, $senha)
{
global $pdo;
$sql = $pdo->prepare("SELECT id_usuarios FROM usuarios WHERE email = :e AND senha = :s");
$sql->bindValue(":e", $email);
$sql->bindValue(":s", md5($senha));
$sql->execute();
if($sql->rowCount() > 0)
{
$dado = $sql->fetch();
session_start();
$_SESSION['id_usuarios'] = $dado['id_usuarios'];
return true;
}
else
{
return false;
}
}
}
?>
Welcome Sorrayla, put in question the way you are making the call of this class.
– André Lins
Your $Pdo variable is null ....
– brunox99x