->fetch() | ->insert() |
DB_DataObject | |
PEAR Manual | |
int $DB_DataObject->count (
string|boolean $countWhat|$whereAddOnly
, boolean $whereAddOnly
)
It performs a select count() request on the tables key column and returns the number of resulting rows. The default condition applied to the count() is a combination of the object variables and whereAdd settings. If the constant DB_DATAOBJECT_WHEREADD_ONLY is passed in as the first parameter then only the whereAdd settings will be used.
string $countWhat - by default count will count on the primary key, if you need to count something else, if you just say DISTINCT, it will count the primiary key prefixed with distinct, or put your own value in (don't forget to escape it if necessary)
boolean $useWhereAddOnly - use only the whereAdd conditions (by default, count will only use both the object settings and the whereAdd conditions)
int|false - number of results or false on an error
This function can not be called statically.
Various examples of using count()
|
Resulting SQL
SELECT count(person.id) AS DATAOBJECT_NUM FROM person WHERE person.name = 'test'; SELECT count(DISTINCT name) AS DATAOBJECT_NUM FROM person; SELECT count(DISTINCT person.id) AS DATAOBJECT_NUM FROM person; SELECT count(person.id) AS DATAOBJECT_NUM FROM person WHERE name like '%test%'; |
->fetch() | ->insert() |
DB_DataObject | |
PEAR Manual | |