Solved

count

Posted on 2000-04-23
5
123 Views
Last Modified: 2010-03-05
how can I get the total number of records in a table of a database?
i would like to use PERL, DBI.
any one can provide me a simple source code?

0
Comment
Question by:stanleyhuen
  • 3
5 Comments
 

Accepted Solution

by:
yovavm101799 earned 10 total points
ID: 2741744
1. Connect to your DB.

2. Perform a 'select* from Table'

3. Get the meta-data $DBI::rows
This variable holds the number of rows affected or returned by the last executed statement

Sample:
------
use DBI;
$dbname = 'DEMO'; $user = 'admin';
$password = 'pass'; $dbd = 'Oracle';

$dbh = DBI->connect($dbname,$user,$password,$dbd) ||
       die "Error connecting $DBI::errstr\n";;


$sth = $dbh->prepare("Select * from Customers");
if ($DBI::err) {
  die STDERR "$DBI::errstr\n";
}
$sth->execute() ;
if ($DBI::err) {
  die STDERR "$DBI::errstr\n";
}
$numOfRecs = $DBI::rows;
print "Total records in table: Customer is $numOfRecs\n";


0
 

Expert Comment

by:mwhuen
ID: 2741967
besides  $DBI::rows, $DBI::err, $DBI::errstr, any other useful functions of DBI?
where can I get more information of these useful functions?
0
 

Expert Comment

by:yovavm101799
ID: 2743055
In case you mean MetaData, well here are some methods used to obtain Meta Data:

$dbh->tables()
fetch a list of all accessible table names

$DBI::rows
The number of rows affected or returned

After executing the statement, use the statement handle to get:

$sth->{NUM_FIELDS}
The number of fields returned by a select

$sth->{NUM_PARAMS}
The number of parameters returned by any query

After a select query, the following attributes contain references to arrays of field-specific information:

$sth->{NAME}
Column names returned by the query

$sth->{NULLABLE}
Booleans indicating whether fields are nullable or not

$sth->{TYPE}
Field types

$sth->{PRECISION}
Floating-point precision of field

$sth->{SCALE}
Field lengths

0
 

Author Comment

by:stanleyhuen
ID: 2744498
thanks yovavm,

i would like to learn more about DBI?

do u know any good resources of DBI?
0
 

Expert Comment

by:yovavm101799
ID: 2746477
Check: "Advanced Perl Programming", By Sriram Srinivasan, published by O'Reilly & Associates.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now