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

I've been out of the mysql and perl game for quite a few years and can't seem to get this right. I have a table with just 3 columns. 'cnt' is one of them. All I want to do is query the table on 'name' and see if name exists. If it does, I want to capture the value of 'cnt'. The table has a record of testName with a value of 2 I added manually. When this script is run it returns empty.
my $pop = qq(SELECT cnt FROM popular WHERE name="testName"); my $sth = $dbh->prepare($pop); $sth->execute() or die $dbh->errstr; my @return; while (@return = $sth->fetchrow_array()) { $count = $return[1]; } print "our return count is $count";
Is it obvious to anyone what I did wrong?

Replies are listed 'Best First'.
Re: Simple mysql select not working
by tangent (Parson) on Nov 22, 2013 at 03:27 UTC
    $count = $return[0]; ?
Re: Simple mysql select not working
by Kenosis (Priest) on Nov 22, 2013 at 03:58 UTC
Re: Simple mysql select not working
by marinersk (Priest) on Nov 22, 2013 at 06:55 UTC
    Double quotes around string value?
    SQL statement not terminated with semi-colon?
Re: Simple mysql select not working
by Anonymous Monk on Nov 22, 2013 at 17:56 UTC
    use Data::Dumper; print STDERR Data::Dumper->Dump( [ $pop, \@return, $count ], [ "pop", "return", "count" ] );
    Use liberally.