2
I don’t know why I made a mistake.
Fatal error: Uncaught Error: Call to Undefined method PDO::fetch() in /opt/lampp/htdocs/myschool.com.br/login.php:24 Trace stack: #0 {main} thrown in /opt/lampp/htdocs/myschool.com.br/login.php on line 24
PHP
use dao\Connection;
session_start();
//Incluir a conexão com banco de dados
include 'application/dao/Connection.php';
date_default_timezone_set("Etc/GMT+3");
if(!empty($_POST)){
$res='';
$email = $_POST['email'];
$senha = $_POST['password'];
$sql = "SELECT idlog, logname
FROM login
WHERE logemail='$email' AND logpassword=md5('$senha')
AND logBlocked = 'no' AND logstatus = 1;";
$res = Connection::getInstance();
$res->prepare($sql);
$res->exec($sql);
$dados = $res->fetch();
if(empty($dados)){
echo "<script>alert('Seu login falhou. LOGIN: [email protected] SENHA: 123');</script>";
} else {
$_SESSION['login'] = true;
$_SESSION['id'] = $dados['id'];
$_SESSION['name'] = $dados['name'];
header("location: index.php");
}
}
You didn’t pass
fetch(PDO::FETCH_ASSOC);

– Rafael Augusto
I think the problem is in prepare, fetch parameters are optional, store
$res->prepare($sql)
; in a variable and instancie exec with it– Felipe Duarte
change
exec
forexecute
– Don't Panic
Rafael Augusto fetch(PDO::FETCH_ASSOC); it was the first thing I tried and it didn’t work.
– user65509
Everton gave running - Uncaught Error: Call to Undefined method PDO::execute(). I think the error ta after exec ...
– user65509
And
Connection::getInstance
returns a PDO instance?– Don't Panic
yes this ta working, it is an instance of Singleton. But this ta working, even because it took a great job to find out how it worked.
– user65509
The error always occurs on line 24 which is the fetch line. This means that the research works and the connection with the bank also works, even because it had wrong the name of a field and there was a warning field name wrong. Then connect with the bank do the select but time to put inside a stick variable..
– user65509
Felipe Duarte also did not work $variable = $res->prepare($sql); $data= $variable->fecth(); and the error in exec. I tried that now ->>> $res->prepare($sql); $stmt->exec($res); $data = $stmt->fetch(); gave the error Call to a Member Function exec() on array
– user65509
Ah and I declared the variable data and stmt as array, I do not know if it is right but the command does not work if the variables are not declared, unknow variable.
– user65509