PHP Error return function

Asked

Viewed 150 times

3

I have the following class with the methods:

<?
class minhaClasse extends database {
public function funcao ($iduser) {
        $date = array($iduser, '1');
        $sql = "SELECT * FROM `tabela` WHERE 'iduser' = ? AND 'princ' = ? ";
        $result = parent::selectDB($sql, $date);
        if (count($result) == 0) {return 0;} else {
            foreach($result as $r) {
                $return =  $r->id;
            }
        }
        return $return;
    }

}
?>

in my main file I have the following functionality

<?
$minhaClasse = new minhaClasse;
$id = $minhaClasse->funcao($idUser); // *
if ($id == 0) {
echo "wem result";
} else {echo $id; }
?>

Good but without any echo nothing I have the following return Array ( [0] => 00000 [1] => [2] => ) Even having or not having resulted in sql. I was analyzing the code and saw that the line that causes the problem is *. The class datebase this ok because I use several other functions with it... How could I fix ?

  • Related http://answall.com/q/79846/101

1 answer

3


The problem for if the syntax, not using simple quotes(') in column or table names, to escape names use backsticks `

WHERE 'iduser' = ? AND 'princ'

Treat the query error by checking the return of execute(), this facilitates dectecting and solving the problem with the query.

if(!$stmt->execute()){
    echo '<pre>';
    print_r($stmt->errorInfo());
}
  • That’s right, my friend, thank you

  • @Augustofurlan, I forgot to mention, avoid using <?, prefer <?php

  • Yes, I use, but how I rode to pass the forum I ended up putting for practicality ...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.