Mam taką funkcje
public function getAll($table) { $sel=$this->pdo->prepare("SELECT * FROM :table"); $sel -> bindValue(':table', $table, PDO::PARAM_STR); $sel -> execute(); $sel->setFetchMode(PDO::FETCH_ASSOC); foreach ($sel as $row){ $data[]=$row; } $sel->closeCursor(); return($data); }
i gdy używam takiego wywołania
getAll('dish');
wyskakuje mi taki błąd. Dlaczego tak się dzieje ? Bo gdy wpiszę na sztywno w zapytaniu
to działa.
SELECT * FROM dish
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''dish'' at line 1' in model.php on line 59