Whether or not you can insert placeholders for column names is database-specific
Perhaps I misunderstand you. I would be quite surprised if any DBD allowed ordinary placeholders to be used to insert column names.
For maximum clarity, assume I get a dynamic column name and desired value like so:
my $colname= 'city';
my $value= 'Toledo';
such that I want to use that to dynamically create the query:
select * from mytable where city = 'Toledo';
and I try to use a placeholder for the column name like so:
my $sth= $dbh->prepare("select * from mytable where ? = ?");
... $sth->execute( $colname, $value );
Then the query that gets run should surely be:
select * from mytable where 'city' = 'Toledo';
which should always return 0 rows since the string 'city' is never equal to the string 'Toledo'.
But the link you provide is indeed an excellent resource for this type of question. Thanks!
|