Hi,
I think both methods have advantages.  It all depends on how much data
you're pulling and the amount of system resources you have available.
If you're returning a couple million rows from the database then
fetchrow would probably be the best way to avoid hogging the system
resources and slowing everything down.  If you're returning only a few
rows then fetchall would probably be more efficient. 

As far as which method would be faster when compared side to side, I'm
not entirely sure.  My experience is somewhat limited with fetchall as
the table I typically deal with are tens of millions, sometimes hundreds
of millions, of rows so fetchrow is what I use to keep from bogging all
the other users on my Unix box.  I think, someone let me know if I'm off
here, that they're probably pretty close to the same speed for the same
amount of data.  The only real difference between the two methods is
where the results of your query are stored.  Fetchrow leaves the data on
the database server to be retrieved while fetchall pulls it all onto the
calling programs OS.

I think you should be able to get the dates for your calendar ok with
fetchrow.  You will have to do multiple fetches so it might be more
efficient to do a fetchall, since it's a small data set.

Hope this helps,
Gordon

-----Original Message-----
From: Etienne [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 14, 2002 9:18 PM
To: [EMAIL PROTECTED]
Subject: fetchall vs fetchrow.. need opinion


Two ways to do the same thing, I'd like your feedback on them please.
It's
my first experience for an interactive webpage with a DB..

# This method (fetchall):

my $res = $dbh->selectall_arrayref("SELECT right(left(evtDtSt,10),2),
evtName from events order by evtDtSt");
for (1..31) # for the 31 days of the month
{ print "$_<br>";
   while ((defined (@{$res})) && (@{$res}[0]->[0] == $_)) # as long as
the
date is the first event of the result's date
   { print "@{$res}[0]->[1]<br>"; # print the event's name
      shift @{$res}; # go to the nest one...
   }
}

# Or this method (fetchrow):

my $sth = $dbh->prepare("SELECT right(left(evtDtSt,10),2), evtName from
events order by evtDtSt");
$sth->execute();
my $i = 1;
while (my @event = $sth->fetchrow_array()) # as long as we have events
left
{ while ($i<=@event[0]) # prints the date as long as we're not at the
first
event's date
  { print "$i<br>";
     $i++;
   }
   print "@event[1]<br>"; # then we print the event's name
}
while ($i<=31) # to finish the month
{ print "$i<br>";
   $i++;
}

#####

Ok, both methods gives the same result...
For my calendar, when I include this into the print of the dates, I was
able
to do it with the fetchall, but I dunno if I would be able to get it to
work
ok with the fetchrow..

Anyways, I'd like to know which method you recommend and why.. or if
both
methods are equivalent.

Etienne

Reply via email to