-5

I am running a PDO query on a MySQL database and I get an error saying there is invalid argument supplied for the foreach. On the frontend, I just pass a string to $questionTable and an integer for $questionID.

What am I doing wrong?

$query = $this->dbConnection->query("SELECT * FROM ('$questionTable') WHERE id = ('$questionID')");
foreach ($query as $row) {
 echo $row;
};
Aman
  • 735
  • 1
  • 6
  • 19
konyv12
  • 716
  • 2
  • 8
  • 23

1 Answers1

-1

Is it because of we shouldn't put '' into the query? I mean: $query = $this->dbConnection->query("SELECT * FROM ($questionTable) WHERE id = ($questionID)");

Minalinsky
  • 277
  • 6
  • 16
  • So the way to extract a parameter's value is by enclosing it with parentheses? That is so weird. – konyv12 Aug 18 '17 at 09:50
  • The parentheses are useless. They only bloat the query. – axiac Aug 18 '17 at 09:51
  • How am I supposed to do it then? – konyv12 Aug 18 '17 at 09:52
  • @konyv12: The last time i write something like this is without parenthese. like SELECT * FROM $tablename WHERE id = $id, but i'm sorry that i'm not sure is there the difference between i used and your case. – Minalinsky Aug 18 '17 at 09:57