Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 14th, 2000, 06:03 AM
chrisdice4 chrisdice4 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Cape Town, WP, South Africa
Posts: 39 chrisdice4 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
How do you count the number of rows returned from your query. at the moment I am trying

$sth = $dbh->prepare("select *
FROM Customer ");

$numrows = $sth->execute;

but it is giving me -1

any ideas

Reply With Quote
  #2  
Old November 21st, 2000, 06:15 PM
amead amead is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 5 amead User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by chrisdice4:
How do you count the number of rows returned from your query. at the moment I am trying

$sth = $dbh->prepare("select *
FROM Customer ");

$numrows = $sth->execute;

but it is giving me -1

any ideas
[/quote]


Using MySQL (and maybe other DBD drivers), there is a method, '$sth->rows();', that you can call afgter the execute(). Using other DBD's (or writing to be portable), you can simply count the rows as you fetch them.

Or you could change the SQL: 'select count(*) from Customer;' and that will rerurn a single scalar that is the number of rows.

BTW, I have no idea where the -1 comes from but I think it's an error code. If so, it's because your SQL isn't legal (you need to end with a semi-colon). And in a UNIX envrionment, the table names are liable to be case sensitive (so make sure customer has a capital C). You've only shown a snippet, but beware that you *must* be checking for failed function calls if you care at all how this application works.

-Alan

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > counting number of rows returned from query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway