Apart from that, you'll be better off using a placeholder in the sql query string, and passing the value to search for as a parameter when you execute the query:
#!/usr/bin/perl use strict; # don't comment this out, and don't capitalize it. use DBI; my $Strain; if ( @ARGV ) { $Strain = shift; # get your target string from the command line } else { print "Please Enter the Strain Name: "; $Strain = <>; chomp $Strain; } $dbh = DBI->connect('dbi:mysql:sampledb','root','******') or die "Connection Error: $DBI::errstr\n"; $sql = <<EOS; # let's make it easier to read while we're at it SELECT feature.fastaId, feature.contigId, feature.orfId, strain.strainName, sequence.ntseq, sequence.aaseq from feature left join strain on feature.id=strain.id left join sequence on feature.id=sequence.id where strainName = ? EOS $sth = $dbh->prepare($sql); $sth->execute( $Strain ) or die "SQL Error: $DBI::errstr\n"; while (@row = $sth->fetchrow_array) { print "@row\n"; }
In reply to Re: Perl -connecting to DB taking query input from user
by graff
in thread Perl -connecting to DB taking query input from user
by MVRS
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |