
November 21st, 2000, 06:15 PM
|
|
Junior Member
|
|
Join Date: Oct 2000
Posts: 5
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
|