On Sat, Aug 25, 2001 at 09:24:25PM -0500, Paul DuBois wrote:
> At 10:07 AM -0700 8/24/01, Katherine Porter wrote:
> >For single values I usually use this DBI function and query:
> >
> > my $val =3D $dbh->selectrow_array("SELECT value FROM tab1 WHERE test=3D=
> >2");
> >
> >However, what if I want to store a bunch of values into an array?
> >
> > my @vals =3D $dbh->?????("SELECT value FROM tab1 WHERE test > 10");
> >
> >What's the syntax I'm missing above? Any help appreciated!
>
> my $ref = $dbh->selectcol_arrayref (single-column query);
> my @val = (defined ($ref) ? @{$ref} : () );
Or just:
my @val = @{ $dbh->selectcol_arrayref(single-column query) || []};
And if you have RaiseError set then you don't need the '|| []' part.
Also, from DBI 1.20 onwards you can now say
$dbh->selectcol_arrayref("select f1, f2 from ...", { Columns=>[1,2] });
and have all the fields flattened into a list. Very handy when building a hash.
But then for building a hash DBI 1.20 also has selectall_hashref() :-)
"The Perl DBI - One call does it all" - almost :-)
Tim.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php