Hello All,

I am using DBI for the first time and am able to use fetchrow_array without any problems. It returns data as I would expect.

My problem arises when I attempt to use fetchrow_hashref. This does not appear to work correctly. I am using Win2K with an Access db.

use DBI; use DBD::ODBC; my $DSN = 'perltest'; my $dbh = DBI->connect("dbi:ODBC:$DSN", '','') || die "$DBI::errstr\n" +; my $sql; # there are three rows that match this select statement $sql = "SELECT * FROM contacts WHERE phone = '8675309'"; $sth = $dbh->prepare($sql); $sth->execute; # this works fine as it displays the first row of data @row = $sth->fetchrow_array; print "@row<br>\n"; # this does not work - displays a blank line $hashrow = $sth->fetchrow_hashref; print "$hashrow{phone} <br>\n"; $sth->finish(); $dbh->disconnect();
I have gone through piles of other examples on this site and others, but still no luck - is it my code? am I blind and missing something??

Any help you could offer would be appreciated

-Jeff


In reply to 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.