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

In reply to Problem Converting SQL term to Perl Variable by monkfan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.