DBI does not do what I expect...
- From: Mark Jaffe <jaffe.mark@xxxxxxxxx>
- Date: Wed, 12 Mar 2008 01:18:35 -0700
Hi,
I am working with a CGI to inspect a database, and I want to include a
count of records in each table in the display. I have two screens
available in the UI: one to list the tables in the d/b, and the other to
show the records in each table. I want to provide a preview of how big
each table is in the table listing, so the code preparing the table list
is doing this:
my $ary_ref = $dbh->selectcol_arrayref ( "SHOW TABLES FROM $db_name" );
# Construct a bullet list using the ul() and li functions. Each item
# is a hyperlink that re-invokes the script to display a particular
table.
my @item;
foreach my $tbl_name (@{$ary_ref}) {
my $url = sprintf ("%s?tbl_name=%s", url(), escape($tbl_name));
my $link = a ({-href => $url}, escapeHTML($tbl_name));
my $sth = $dbh->prepare ( qq (
SELECT COUNT(*) FROM $tbl_name ) );
my $rv = $sth->execute();
my $rows = $sth->rows;
push (@item, li ($link . " $rows in table" ) );
}
print ul (@item);
But when I execute the SQL, I only get "1" returned for each "$rows",
rather than what I expect, the number of rows.
Why is this not working for me?
Thanks,
Mark
.
- Follow-Ups:
- Re: DBI does not do what I expect...
- From: Frank Seitz
- Re: DBI does not do what I expect...
- Prev by Date: ANNOUNCE: Text::CSV_XS 0.37
- Next by Date: Re: DBI does not do what I expect...
- Previous by thread: ANNOUNCE: Text::CSV_XS 0.37
- Next by thread: Re: DBI does not do what I expect...
- Index(es):
Relevant Pages
|
|