0
I have my class:
public function SQL($sql, $arrayParams = null, $fetchAll = TRUE)
{
try {
// Passa a instrução para o PDO
$stm = $this->pdo->prepare($sql);
// Verifica se existem condições para carregar os parâmetros
if (!empty($arrayParams)){
// Loop para passar os dados como parâmetro cláusula WHERE
$cont = 1;
foreach ($arrayParams as $valor){
$stm->bindValue($cont, $valor);
$cont++;
}
}
// Executa a instrução SQL
$stm->execute();
// Verifica se é necessário retornar várias linhas
if ($fetchAll){
$dados = $stm->fetchAll(\PDO::FETCH_OBJ);
}else{
$dados = $stm->fetch(\PDO::FETCH_OBJ);
}
$this->nRows = count($dados);
return $dados;
} catch (PDOException $e) {
echo "Erro: " . $e->getMessage();
}
}
In another class I’m using it as follows:
$db = Conexao::getInstance();
$pdo = Base::getInstance($db, "pre_cadastro");
$sql = "SELECT nome, token FROM pre_cadastro WHERE email = ?";
$res = $pdo->SQL($sql, array('[email protected]'), false);
$nome = $res->nome; //linha 83
$token = $res->token; //linha 84
echo $nome."<br>";
echo $token;
As I use it for in an ajax, ta me returning this error:
Notice: Trying to get Property of non-object in C: Apache24 htdocs class Sendmail.php on line 83
Notice: Trying to get Property of non-object in C: Apache24 htdocs class Sendmail.php on line 84
Line 83) $nome = $res->nome;
Row 84) $token = $res->token;
I know they are notices, but they are returning me this error in AJAX. And they are not really printing anything..
What are lines 83 and 84 of the Sendmail.php class?
– Jeferson Almeida
I edited it. I forgot to make it explicit
– Hermus
Query may have returned empty.
– rray
You could give a
var_dump($res);
and check the result?– Jeferson Almeida