None of my querys return values, and I have data in my bank. What might be happening in my code that is resulting in this? Follow the Code:
<?php
require_once("Usuario.php");
require_once("Conexao.php");
require_once("Crud.php");
class DaoUsuario implements Crud{
private $status;
private $tabela;
public function __construct(){
$this->$status = conexao::getConexao();
$this->$tabela = "usuario";
}
public function consultar($id) {
$query = "SELECT * FROM {$this->tabela} WHERE id=:id";
try{
$operacao = $this->status->prepare($query);
$operacao->bindValue("id:",$id, PDO::PARAM_INT);
$operacao->execute();
$getRow = $operacao->fetch(PDO::FETCH_OBJ);
$usuario = $getRow->usuario;
$senha = $getRow->senha;
$objeto = new Usuario($id, $usuario, $senha);
$objeto->setId($id);
return $objeto;
} catch (PDOException $erro) {
echo $erro->getMessage();
}
}
public function criar($objeto) {
$id = $this->getNewIdUsuario();
$usuario = $this->getUsuario();
$senha = $this->getSenha();
$query = "INSERT INTO {$this->tabela} (id,usuario,senha) VALUES(:usuario, :senha)";
try{
$operacao = $this->status->prepare($query);
$operacao->bindValue(":id",$id, PDO::PARAM_INT);
$operacao->bindValue(":usuario",$usuario, PDO::PARAM_STR);
$operacao->bindValue(":senha", $senha, PDO::PARAM_STR);
if($operacao->execute()){
if($operacao->rowCount() > 0){
$objeto->setId($id);
return true;
} else{
return false;
}
}else{
return false;
}
} catch (PDOException $erro) {
echo $erro->getMessage();
}
}
public function deletar($parametro) {
$query = "DELETE FROM {$this->tabela} WHERE id=:id";
try{
$operacao = $this->status->prepare($query);
$operacao->bindValue(":id",$id, PDO::PARAM_INT);
if($operacao->execute()){
if($operacao->rowCount() > 0){
return true;
}else{
return false;
}
}else{
return false;
}
} catch (PDOException $erro) {
echo $erro->getMessage();
}
}
public function modificar($objeto) {
$id = $objeto->getId();
$usuario = $objeto->getUsuario();
$senha = $objeto->getSenha();
$query = "UPDATE {$this->tabela} SET usuario=:usuario, senha=:senha WHERE id=:id";
try{
$operacao = $this->status->prepare($query);
$operacao->bindValue(":id",$id, PDO::PARAM_INT);
$operacao->bindValue(":usuario",$usuario, PDO::PARAM_STR);
$operacao->bindValue(":senha",$senha, PDO::PARAM_STR);
if($operacao->execute()){
if($operacao->rowCount() > 0){
return true;
}else{
return false;
}
}else{
return false;
}
} catch (PDOException $erro) {
echo $erro->getMessage();
}
}
private function getNewIdUsuario(){
$query = "SELECT MAX(id) AS id FROM {$this->tabela}";
try{
$operacao = $this->status->prepare($query);
if($operacao->execute()){
if($operacao->rowCount() > 0){
$getRow = $operacao->fetch(PDO::FETCH_OBJ);
$idReturn = (int) $getRow->id + 1;
return $idReturn;
}else{
throw new Exception("Ocorreu um erro no Banco de Dados");
exit();
}
}else{
throw new Exception("Ocorreu um erro no Banco de Dados");
exit();
}
} catch (PDOException $erro) {
echo $erro->getMessage();
}
}
}
When I go to a session:
<?php
session_start();
require_once('../Classes/DaoUsuario.php');
$autentificar = new DaoUsuario;
$usuario = $_POST['usuario'];
$senha = $_POST['senha'];
$autentificar->consultar($id);
if(PDO::FETCH_ASSOC($autentificar)>1){
$_SESSION['id'] = $id;
$_SESSION['usuario'] = $usuario;
header('Location: painel-de-controle.php');
}else{
header('Location: administrador.php');
session_destroy();
}
?>
My connection:
<?php
class Conexao {
private static $conexao;
private function __construct(){}
private function __clone() {}
private function __wakeup() {}
public static function getConexao(){
if(!isset(self::$conexao)){
try{
$banco = 'mysql:host=meu_servidor;dbname=nome_banco';
$usuario = 'meu_usuario';
$senha = 'minha_senha';
}catch (PDOException $erro){
echo $erro->getMessage();
//Encerrando
exit();
}
}
return self::$conexao;
}
}
And returns the following error: Fatal error: Uncaught Error: Call a member function prepare () on null in DaoUsuario.php on line 18