SPUG: DBI bind_param in MySQL

Colin Meyer cmeyer at helvella.org
Fri Nov 26 16:53:51 CST 2004

On Fri, Nov 26, 2004 at 02:16:45PM -0800, Michael R. Wolf wrote:
> When I try this, I get a literal (e.g. "first_name") in the output,
> not the value of the field.
>     my $sth = $dbh->prepare("SELECT ? FROM bod")
>       or die "Cannot create sth: $DBI::errstr";
>     $sth->bind_param(1, "first_name");
>     $sth->execute()
>       or die "Cannot execute statement: $DBI::errstr";
> Am I missing something important, or is this feature unavailable with
> MySQL?

Every relational database that I have used (including MySQL) only lets
you use placeholders for values, not for identifiers (e.g. column or
table names).

You could, for example:

  my $sth = $dbh->prepare( <<'End_of_SQL' );
    SELECT first_name
    FROM bod
    WHERE first_name LIKE ?  

  $sth->execute( 'Mi%' );


More information about the spug-list mailing list