0

I have a PDO query like this.

$query=$this->con->prepare('SELECT ? FROM ? ');
$query->execute(array($rows,$table));
/*$rows="*"; $table="category";*/

Everything is OK in the coding. But when PDO executing my query it parse it as,

SELECT '*' FROM 'category'

So it's a wrong SQL statement.

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 ''category'' at line 1

Please help me. How to prevent PDO from inserting the 's.

  • 1
    You cannot use PDO placeholders for things that affect the query structure. They are only valid where string/numeric literal are allowed. – DCoder Apr 03 '14 at 04:44
  • Parameter binding only works on parameters, not database identifiers. You can only bind values, not table or column names – Phil Apr 03 '14 at 04:44
  • did you use the code like `select '*' from 'category'` means try to remove the `''`(single quotes) in the just like `select * from category` – jmail Apr 03 '14 at 05:07
  • Check `print_r(array($rows, $table))` and/or `print_r($table)`. I think the `category` is quoted there already. If so than leave PDO alone and get rid of the quotes there. – pawel7318 Apr 03 '14 at 05:20

0 Answers0