I'm a beginner. I wrote this and I have been told my find() method had security vulnerabilty. I thougt that the if else of my queryType method prevented from Sql injections attempts.
public function queryType(string $sql, array $attributes = null)
{
## instance of Database singleton
$this->Database = Database::getInstance();
if($attributes !== null) {
## if attr, prepared request
$query = $this->Database->prepare($sql);
$query->execute($attributes);
return $query;
}else{
## else, simple request
return $this->Database->query($sql);
}
}
## SECURITY ISSUE /!\ ?? queryType if/else doesn't prevent ??
public function find(int $id)
{
return $this->queryType("SELECT * FROM {$this->table} WHERE id = $id")->fetch();
}
How can I solve it ?