|Perl: the Markov chain saw|
Re: SELECT COUNT and DBI: rowsby gmax (Abbot)
|on Sep 28, 2003 at 20:56 UTC||Need Help??|
It works for me, if I add username and password to your connect statement.
You say that your script produces no value. Does it mean that the $total variable is empty? It is not.
It looks like what you posted is not the actual code you're using. Therefore, a few questions are necessary:
Furthermore, the $sth->rows method doesn't return the number of rows in a table, but the number of rows affected by your statement, when your SQL contains modifying commands such as UPDATE, INSERT, DELETE.
That method returns sometimes the number of records from a SELECT statement, but it is driver dependant, and not reliable, as you can see from the DBI docs. Using MySQL, it should return the number of rows if you execute a SELECT that fetches all the rows in your table, but a simple COUNT is less expensive.
To count the number of rows, then, you need to use COUNT(*), as you did.
Please read the above Tutorials, and then provide more information about your case.