$sql = $db->prepare("DELETE FROM :table WHERE :col = :id") ;
$sql->execute(['table' => 'TableName', 'col' => 'id', 'id' => $id]) ;
it fails, I think because it puts the table and column names in ‘quotes’.
Is there a way to do this?
The idea is I execute the query twice, to delete an entry from two tables.
Or maybe I’m going about this the wrong way, and should use JOIN or something to delete from the main table and the LUT in one query?
I had it working with two prepare lines and two execute lines. I thought maybe I could lose one prepare line by doing that.
But formatting like you have will reduce it to just two lines.
Connect the tables with a DELETE CASCADE foreign key and DELETE only from one (parent) table (what @felgall suggested - best solution). If it is impossible then simply execute two separate queries in a transaction.