PHP Error returning function

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 with no echo I have the following return Array ( [0] => 00000 [1] => [2] => ) Even though it did or did not work in sql. I was analyzing the code and saw that the line that causes the problem is a *. The class datebase is ok because I use several other functions with it ... How could I fix it?

    
asked by anonymous 16.12.2015 / 13:45

1 answer

3

The problem for the syntax is not using single 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() , which makes it easy to decrypt and resolve the problem with the query.

if(!$stmt->execute()){
    echo '<pre>';
    print_r($stmt->errorInfo());
}
    
16.12.2015 / 14:02