http://www.perlmonks.org?node_id=611439

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

Hi,
I have no problem performing such query under mysql prompt:
mysql> SELECT Symbol FROM gene_info RIGHT JOIN gene2go ON(gene_info.`G +eneID`= gene2go.`GeneID`) WHERE GO_Term='proteasome localization'; +-------------+ | Symbol | +-------------+ | SPBC1734.06 | | SPBC646.09c | | cut8 | | rhp6 | | SPAC1420.03 | | SPAC3G6.02 | | rpn5-b | | SPBC19C7.02 | +-------------+ 8 rows in set (2 min 19.11 sec)
But when I run this Perl script:
use strict; use Data::Dumper; use Carp; use DBI; my $dsn = 'localhost'; my $user = 'ewijaya'; my $password = 'ewijaya'; my $dbh = DBI->connect('dbi:mysql:motif_finder','monkfan','monkpwd') or die "Connection Error: $DBI::errstr\n"; my $go_term = "proteasome localization"; my $sql = "SELECT Symbol FROM gene_info RIGHT JOIN gene2go ON(gene_inf +o.`GeneID`= gene2go.`GeneID`) WHERE GO_Term=$go_term"; my $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; while ( my @row = $sth->fetchrow_array ) { print "@row\n"; }
It gives:
:!perl search_gene.pl DBD::mysql::st execute failed: You have an error in your SQL syntax; c +heck the manual that corresponds to your MySQL server version for the + right syntax to use near 'localization' at line 1 at search_gene.pl +line 21. SQL Error: You have an error in your SQL syntax; check the manual that + corresponds to your MySQL server version for the right syntax to use + near 'localization' at line 1
How can we correctly assign SQL command in the Perl Script?

Regards,
Edward