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.
Update
The error is NOT in the "AS" keyword as stated by ronzomckelvey. Such keyword is perfectly legal and functional in MySQL. (Updated again - OK, I see that both Zaxo and dws have pointed out that in detail.)
_ _ _ _ (_|| | |(_|>< _|
In reply to Re: SELECT COUNT and DBI: rows
by gmax
in thread SELECT COUNT and DBI: rows
by perleager
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |