Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

variables inside SQL statements

by Anonymous Monk
on Oct 10, 2000 at 23:30 UTC ( #36102=perlquestion: print w/ replies, xml ) Need Help??
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.

Comment on variables inside SQL statements
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://36102]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (10)
As of 2014-10-31 12:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (217 votes), past polls