Well, the netbeans does not acknowledge any errors, but when I try to run it always gives an error in the browser, does anyone know what's wrong? can you tell me how to use the pdo connection of the parent class constructor method in the child class?
Connection Class:
<?php
class Conexao {
protected $Conecta;
private $host = "localhost";
private $dbname = "classificados";
private $user = "root";
private $pass = "";
public function __construct() {
try {
$this->Conecta = new PDO("mysql:host={$this->host};dbname={$this->dbname}", "{$this->user}", "{$this->pass}");
return $this->Conecta;
} catch (PDOException $e) {
echo $e->getMessage();
}
}
}
**Classe Sessao**
<?php
require_once "BD/Conexao.class.php";
class Sessao extends Conexao {
private $verificaUser;
public function setUsuario($email, $senha) {
$this->verificaUser = parent::prepare("SELECT email, senha FROM usuarios WHERE cl_email = :email AND senha = :senha");
$this->verificaUser->bindValue(":email", $email);
$this->verificaUser->bindValue(":senha", $senha);
$this->verificaUser->execute();
return $this->verificaUser->rowCount();
}
public function getUsuario() {
return $this->setUsuario();
}
}
$teste = new Sessao;
$teste->setUsuario("[email protected]", "123");
echo $teste->getUsuario();
Error:
Fatal error: Uncaught Error: Call to undefined method Conexao::prepare() in /opt/lampp/htdocs/classificados/model/Sessao.class.php:10 Stack trace: #0 /opt/lampp/htdocs/classificados/model/Sessao.class.php(24): Sessao->setUsuario('[email protected]', '123') #1 {main} thrown in /opt/lampp/htdocs/classificados/model/Sessao.class.php on line 10
Lucas saw this and returned this error:
Warning: Missing argument 1 for Session :: setUsuario (), called in /opt/lampp/htdocs/classificados/model/Sessao.class.php on line 18 and defined in /opt/lampp/htdocs/classificados/model/Sessao.class.php on line 9
Warning: Missing argument 2 for Session :: setUsuario (), called in /opt/lampp/htdocs/classificados/model/Sessao.class.php on line 18 and defined in /opt/lampp/htdocs/classificados/model/Sessao.class.php on line 9
Notice: Undefined variable: email in /opt/lampp/htdocs/classifieds/model/Sessao.class.php on line 11
Notice: Undefined variable: password in /opt/lampp/htdocs/classified/model/Sessao.class.php on line 12 0