Hello, i am trying to run a query based on user input. I’m using prepared statements, but something is wrong in my code, and i just cannot understand what. My code is as follows:
[php]
function sortByClass(String $class) {
$candidates=array();
$stmt = $this->db->prepare("SELECT lastName, surName, class, phone, FROM people WHERE class =:class ORDER BY lastName");
$stmt->bindParam(':class', $class, PDO::PARAM_INT);
$stmt->execute();
while ($number= $stmt->fetchObject('Candidate')) {
$candidates[] = "$number";
}
return $candidates;
}
[/php]
I notice that if i in my query replace WHERE class =:class with WHERE class = ‘real_class_name’, i get an array returned with the desired results. So i believe the problem lies with the prepared statement…somewhere. (I translated this into english, i’m aware that i should not use the name “class” as variable, the naming is different in my code)