Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Quoting in DBI sql query for on the fly query

by htoug (Deacon)
on Oct 29, 2004 at 12:01 UTC ( #403699=note: print w/ replies, xml ) Need Help??


in reply to Quoting in DBI sql query for on the fly query

In your second example the terminating " is missing.

You should use $dbh->quote($line) to ensure that the quoting is correct. This incidentally guards against SQL-injection attacks. You need a chomp to remove the trailing newline in $line

You should write something like (untested):

my @lines = <DATA>; my $line; foreach $line ( @lines ) { chomp($line); #prepare and execute SQL statement $sqlstatement="SELECT Table1.Name, Table1.Address, Table1.City, Table1.State, Table1.ZIP, Table1.Phone FROM Table1 WHERE Table1.BusType = ".$dbh->quote($l +ine); $sth = $dbh->prepare($sqlstatement); }


Comment on Re: Quoting in DBI sql query for on the fly query
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2014-08-30 06:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (291 votes), past polls