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);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Quickest way of fetching a Single row and column in MySQL using DBI
by perrin (Chancellor) on Aug 07, 2006 at 16:15 UTC | |
by cees (Curate) on Aug 07, 2006 at 18:01 UTC | |
by jZed (Prior) on Aug 09, 2006 at 01:59 UTC |
In Section
Seekers of Perl Wisdom