Q:

How to do parametrize the table name in a PDO statement?

Problem
I get a PDO syntax error when running a PDO statement where the table name is parametrized, like in
$sql = 'DELETE FROM :table_name';
$query = $this->db->prepare($sql);
$query->execute(array(':table_name' => "mytable"));

I could reproduce the problem with SELECT etc., so it's a general issue.
I tried to write it with backticks, with database name in front of it, a combination of both etc, nothing works.
Question
How to do this ?

A:

You cannot parameterize table names, column names, or anything in an IN clause (it'll have to be bound separately). See this comment on php.net.
See also: Can PHP PDO Statements accept the table or column name as parameter? 

