On Sat, Dec 07, 2002 at 02:08:28PM -0500, Amittai Aviram wrote:
> I have been learning a bit about the Perl DBI MySQL API.  This API offers
> several ways of fetching the results of a query.  Among these,
> fetchrow_array returns a numbered array, while fetchrow_arrayref returns a
> reference to an array.  When would you want to use a reference to an array
> rather than the array itself to hold a row of results from a query?  Thanks!

If you do something like:
my $sth = $dbh->prepare('select mycolumn from atable');
$sth->execute();
while (my @res = $sth->fetchrow_array) {
   # do something
}

the 'while' loop wil break the moment you encounter a 'NULL' value in
'mycolumn': the NULL translates to 'undef' in perl, which is false, which 
brakes the loop.  An arrayref wil always be true.


+ an arrayref might be faster (AFAIK, DBI re-uses the array the reference
references to, so it does not need to build the whole array for every
single row, just replace the new values).


Good luck.
Harmen


-- 
                               The Moon is Waxing Crescent (15% of Full)
                                           nieuw.nl - 2dehands.nl: 57600

---------------------------------------------------------------------
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

Reply via email to