Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have some SQL that I want to run within/outside (don't care which one) a Perl script. I can connect to svrmgrl and log in fine, but I need to use Perl variables (for paths) within the SQL statements.

Replies are listed 'Best First'.
Re: variables inside SQL statements
by indigo (Scribe) on Oct 11, 2000 at 02:24 UTC
    Note - Interpolating variables into SQL is bad. Instead, use 'bind' variables, like so:
    my $sql = 'INSERT INTO table ( path ) VALUES (:1)'; # Compile sql my $sth = $dbh->prepare($sql) or die $dbh->errstr; # Bind path to :1 $sth->execute('/path/to/this') or die $dbh->errstr;
        You mean there are databases other than mySQL and Oracle? I don't understand. :)
Re: variables inside SQL statements
by dragonchild (Archbishop) on Mar 28, 2004 at 17:05 UTC
    Go to the DBI docs and look up placeholders.