0
Good people I am making a Login system, but I believe, I have a problem with the connection with the database, because only returns the value false, and true involves a query with the BD... below follows the Cód.:
This is the connection to the database:
<?php
function __autoload($class){require_once"{$class}.class.php";}
abstract class ConDB{
private $cnx;
private function setConn(){
return
is_null($this->cnx)?
$this->cnx=new PDO('mysql:host=localhost;dbname=silkgra','admin','admin'):
$this->cnx;
}
public function getConn(){
return $this->setConn();
}
}
$lgn=new Login;
var_dump($lgn->setLogin('[email protected]','12345678'));
?>
This is the Cód. of Login:
<?php
class Login{
private $vem,$vsh,$cpt,$crud,$email,$senha,$log,$dds;
public function setLogin($email,$senha){
$this->vem=new ValidaEmail;
$this->vsh=new ValidaSenha;
$this->cpt=new Cripto;
$this->crud=new CRUD;
$this->email=$this->vem->setValidaEmail($email);
$this->senha=$this->vsh->setValidaSenha($senha);
$this->log=$this->senha==$senha?
$this->crud->select('idUsuario','usuario','WHERE email=? && senha=?',
array($this->email,$this->cpt->setCripto($this->senha))):
FALSE;
return $this->log->rowCount();
if($this->log && $this->log->rowCount()>0){
foreach($this->log as $this->dds){
$_SESSION['logado']=$this->dds;
return true;
//header('location:../../admin/');
}
} else {
return 'Acesso Negado...';
}
}
}
?>
THIS IS THE PRINT OF THE DATABASE:
happens q when use data q are already in the database does not return anything, but I have these data stored
when I go to do the test appears the following error:
Fatal error: Call to a Member Function rowCount() on Boolean in C: xampp htdocs silkgra require class Login.class.php on line 18
Ae rray take a look, this is the CRUD file I made to make the connection:
<?php
class CRUD extends ConDB{
private $query;
private function prepExec($prep,$exec){
$this->query=$this->getConn()->prepare($prep);
$this->query->execute($exec);
if(!$pdo->execute()){ print_r($pdo->errorInfo()); die('deu ruim');}
}
public function insert($table,$cond,$exec){ // o $cond aqui remete a condição
$this->prepExec('INSERT INTO '.$table.' SET '.$cond.'',$exec);
return $this->getConn()->lastInsertId();
}
public function select($fields,$table,$cond,$exec){
$this->prepExec('SELECT '.$fields.' FROM '.$table.' '.$cond.'',$exec);
return $this->query;
}
public function update($table,$cond,$exec){
$this->prepExec('UPDATE '.$table.' SET '.$cond.'',$exec);
}
public function delete($table,$cond,$exec){
$this->prepExec('DELETE FROM '.$table.' '.$cond.'',$exec);
}
}
?>
Ai rray, returned this brother
you need what inside
$this->crud->select()
I imagine you have aexecute()
PDO, it must be failing, can see the error (if it exists) like this:if(!$pdo->execute()){ print_r($pdo->errorInfo()); die('deu ruim');}
remember to trade$pdo
by its variable that receives theprepare()
– rray
ae rray that Cód. line in which part of Cód. do I place? sorry the many questions mano, but it happens q i’m starting to study php and mysql agr, tendeu.. sorry msm
– SheepSociety
Do the test in the method
prepExec()
– rray
ae rray updated there bro gave 2 msg
– SheepSociety