Can I use placeholders for tables and columns in PDO?

Unfortunately, you can’t.

Thus, old good manual formatting is the only way with vanilla PDO. Note that identifier formatting rules are different from string formatting!

In your case I’d just run two queries.

$db->prepare("DELETE FROM table1 WHERE col = ?")->execute([$id]);
$db->prepare("DELETE FROM table2 WHERE col2 = ?")->execute([$id]);

See - it is not as much writing as one would want to get rid of.

If you still want to make this code as concise as possible, look towards an ORM, with which it will be just

Table1::find($id)->delete();
Table2::find($id)->delete();

You may want to take a look at Eloquent ORM at this chapter from the excellent Code Bright by Dayle Rees,

1 Like