Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: SELECT COUNT and DBI: rows

by gmax (Abbot)
on Sep 28, 2003 at 20:56 UTC ( #294795=note: print w/replies, xml ) Need Help??

in reply to SELECT COUNT and DBI: rows

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.

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.)

_ _ _ _ (_|| | |(_|>< _|

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://294795]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2022-12-06 00:59 GMT
Find Nodes?
    Voting Booth?

    No recent polls found