Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Failure to Recognize Field in DBI MySQL access

by monkfan (Curate)
on Apr 22, 2007 at 14:08 UTC ( #611370=perlquestion: print w/ replies, xml ) Need Help??
monkfan has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,
Why was my script below:
use strict; use Data::Dumper; use Carp; use DBI; my $dsn = 'localhost'; my $user = 'monkfan'; my $password = 'monkfan'; my $dbh = DBI->connect('dbi:mysql:motif_finder','monkfan','monkpwd') or die "Connection Error: $DBI::errstr\n"; my $sql = "SELECT Symbol FROM gene2go WHERE GeneID=812222"; my $sth = $dbh->prepare($sql); $sth->execute or die "SQL Error: $DBI::errstr\n"; while ( my @row = $sth->fetchrow_array ) { print "@row\n"; }
Giving such error message
:!perl test_dbi.pl + DBD::mysql::st execute failed: Unknown column 'Symbol' in 'field list' + at test_dbi.pl line 21. SQL Error: Unknown column 'Symbol' in 'field list'
Even though it is clearly shown in the SQL query below which is equivalent to above Perl script, is actually working?
mysql> select Symbol from gene_info where GeneID = "812222"; +-----------+ | Symbol | +-----------+ | PF14_0640 | +-----------+ 1 row in set (13.06 sec) mysql> show tables; +------------------------+ | Tables_in_motif_finder | +------------------------+ | gene2go | | gene_info | +------------------------+ 2 rows in set (0.00 sec) mysql> show databases; +--------------+ | Database | +--------------+ | motif_finder | +--------------+ 1 rows in set (0.00 sec)

Regards,
Edward

Comment on Failure to Recognize Field in DBI MySQL access
Select or Download Code
Re: Failure to Recognize Field in DBI MySQL access
by ikegami (Pope) on Apr 22, 2007 at 14:43 UTC

    Your Perl query is different than your MySQL client query. One uses table gene2go while the other uses gene_info.

    I don't know if MySQL cares about that, but one query treats GeneID as a string field, while the other treats GeneID as a number field.

Re: Failure to Recognize Field in DBI MySQL access
by CountZero (Bishop) on Apr 22, 2007 at 16:40 UTC
    Are you sure the table "gene2go" has a field "Symbol"?

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2014-10-21 07:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (98 votes), past polls