Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Problem w zapytaniu (PDO)
brzoza91
post
Post #1





Grupa: Zarejestrowani
Postów: 39
Pomógł: 4
Dołączył: 9.05.2012

Ostrzeżenie: (0%)
-----


Witam
Mam taką funkcje

  1. public function getAll($table) {
  2. $sel=$this->pdo->prepare("SELECT * FROM :table");
  3. $sel -> bindValue(':table', $table, PDO::PARAM_STR);
  4. $sel -> execute();
  5. $sel->setFetchMode(PDO::FETCH_ASSOC);
  6. foreach ($sel as $row){
  7. $data[]=$row;
  8. }
  9. $sel->closeCursor();
  10.  
  11. return($data);
  12. }


i gdy używam takiego wywołania

  1. getAll('dish');

wyskakuje mi taki błąd. Dlaczego tak się dzieje ? Bo gdy wpiszę na sztywno w zapytaniu
  1. SELECT * FROM dish
to działa.


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

Ten post edytował brzoza91 20.07.2012, 20:45:09
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 25.08.2025 - 05:34