in reply to DBI, From PHP to Perl
$sth->rows() is what you want, but you should be advised that $sth->rows() is not guaranteed to give you an accurate count until you fetch all of the rows in the result set. With MySQL you should be fine calling $sth->rows() before you fetch all of the rows from the database unless you set the mysql_use_result attribute on the sth, but then again you would have the same problem with php if you used mysql_use_result().
So you can do something like this:$sth = $dbh->prepare($sql); while (my @results = $sth->fetchrow_array) { do_something(@results) } my $count = $sth->rows();
You probably will also want to 'use strict' and 'use warnings' in your code. They will make your code easier to debug because they keep you from shooting yourself in foot in some of the most common ways. One other thing you might want to look at is Template-Toolkit or HTML::Template both of wich will allow you to remove the html from you code, so that your program will be easier to read.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: DBI, From PHP to Perl
by dstefani (Sexton) on Nov 08, 2003 at 19:29 UTC | |
by pinetree (Scribe) on Nov 09, 2003 at 03:53 UTC |