Fellow Monasterians>/p>

I'm trying to learn and apply the selectrow/col/all methods in the DBI. Most everything has worked, with the exception below. The table in question, 'users' has a row that matches the criteria. What am I missing? Thanks! (Googled and Super Searched)

Works:

my $stmt = "SELECT * FROM subscriber_contact WHERE subscriber_id = ?"; my %customer = % { $dbh->selectrow_hashref($stmtm, undef, $user_name)) + };

Doesn't work:

my $stmt = "SELECT * FROM users WHERE username = ?"; my %userdata = % { $dbh->selectrow_hashref($stmt, undef, $user_name) } +;

Returns error:

Can't call method "selectrow_hashref" on an undefined value

From the DBI doc (but not sure if it applies here)

If called in a scalar context for a statement handle that has more than one column, it is undefined whether the driver will return the value of the first column or the last. So don't do that. Also, in a scalar context, an undef is returned if there are no more rows or if an error occurred. That undef can't be distinguished from an undef returned because the first field value was NULL. For these reasons you should exercise some caution if you use selectrow_array in a scalar context.

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

In reply to DBI returning error on selectrow_hashref by bradcathey

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.