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.
In reply to DBI returning error on selectrow_hashref by bradcathey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |