Pdo::count
SELECTの行数を数えるクエリを組み立てます
説明
public self Pdo::count( string $table )
selectが組み立てるSELECTを囲んで、Select Count(*) as number_of_records From (...) AS "count_temp"を組み立てます。そのため、条件、JOIN、GROUP BYがあっても正しく数えます。結果はone()['number_of_records']で読みます。
引数
| 名前 | データ型 | デフォルト | 備考 |
|---|---|---|---|
| $table | string | 対象テーブル名 |
例
Controller
$db = new \Fegg\Database\Pdo();
$record = $db->setWhere('category = ?', 2)->count('cms_news')->execute()->one();
$count = (int) $record['number_of_records'];