in reply to Re: Quickest way of fetching a Single row and column in MySQL using DBI
in thread Quickest way of fetching a Single row and column in MySQL using DBI
Although your version works, it is potentially open to an SQL injection attack through the $username variable. With DBI that is easy to avoid by using placeholders. Also, I think you want selectrow_array (selectrow_arrayref returns a reference to an array, wheras selectrow_array will return a list, or just a scalar value if you are selecting a single column).
my $id = $dbh->selectrow_array("SELECT id FROM users where username = +?", {}, $username);
In Section
Seekers of Perl Wisdom