int $DB_DataObject->count (
string|boolean $countWhat|$whereAddOnly
, boolean $whereAddOnly
)
これは、表のキーカラムによる select count() リクエストを実行し、 結果の行数を返します。 count() に適用されるデフォルトの条件は、オブジェクト変数と whereAdd の設定内容の組み合わせです。 もし、定数 DB_DATAOBJECT_WHEREADD_ONLY が第1パラメータに指定された場合、 whereAdd の設定内容だけが使用されます。
string $countWhat
-
デフォルトカウントは、主キーをカウントします。
もし何か他をカウントする必要がある場合で、単純に DISTINCT
を指定する場合は DISTINCT を前に付けた主キーをカウントします。
その他の場合は独自の値をカウントします
(エスケープが必要な場合、忘れないようにしてください) 。
boolean $useWhereAddOnly
-
whereAdd 条件のみ使用するかどうかを指定します
(デフォルトでは、count オブジェクトの設定内容と
whereAdd の条件の両方が使用されます) 。
int|false
- 結果の数もしくは失敗時に false
This function can not be called statically.
オブジェクト変数に基づいたデータの簡単な検索とフェッチ
<?php
/* using property values */
$person = new DataObjects_Person;
$person->name = "test"
$total = $person->count();
echo "There are {$total} people with a name like test";
/* using countWhat */
$person = new DataObjects_Person;
$total = $person->count('DISTINCT name');
echo "There are {$total} names in the database";
/* using countWhat value = DISTINCT */
$person = new DataObjects_Person;
$total = $person->count('DISTINCT');
echo "There are {$total} names in the database";
/* using whereOnly */
$person = new DataObjects_Person;
$person->name = "test";
$person->whereAdd("name like '%test%");
$total = $person->count(DB_DATAOBJECT_WHEREADD_ONLY);
echo "There are {$total} names in the database";
?>
結果の SQL