You have no syntactical errors in your code, but there are a couple of safeguards that might help you to find what is going wrong. First - use strict! This will catch errors in variables names and types, which you don't appear to have. Next, don't use 'SELECT *'. Instead, explicitly list the field names you are selecting. This will help prevent you from trying to access mispelled field names.

But, both of these do not appear to hamper your code at all - instead, i'll wager that there is only one record with the the phone number 8673509 (Jenny!).

Try this instead - take out the WHERE clause and run your code again, i'll bet you get something this time. If not then replace the fetchrow_array fetch with the fetchrow_hashref fetch.

Also, add use strict; at the top with your other use statements and add my to each new occurance of a variable. You have one for $DSN, $dbh, and $sql - add them to $sth, @row, and $hashrow - it is just good practice to do so.

<UPDATE>
usrbinperl++ and jsprat++ This is all the more reason to always, always use strict: because the code would not even compile due to the fact that you forgot two simple characters: - and > (jeffa needs to quit wagering, he keeps losing) ;)
</UPDATE>

Lastly, use Data::Dumper to inspect what fetchrow_hashref returns. Quick and easy:

use DBI; use Data::Dumper; use strict; my $dbh = DBI->connect( qw(DBI:vendor:database:host user pass), {RaiseError=>1} ); # setting RaiseError to true will cause your script to # die with an error message from all database errors my $sth = $dbh->prepare(" select * from mp3.songs limit 200 "); $sth->execute; my $hashrow = $sth->fetchrow_hashref; print Dumper $hashrow; # or just print Dumper $sth->fetchrow_hashref;

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) Re: DBI and fetchrow_hashref by jeffa
in thread DBI and fetchrow_hashref by jeff867

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.