メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Pdo::count

Set select count query

Description​

public self Pdo::count( string $table )

Builds Select Count(*) as number_of_records From (...) AS "count_temp" around the SELECT that select would build, so conditions, joins and groups are counted correctly. Read the result with one()['number_of_records'].

Arguments​

NameData typeDefaultRemarks
$tablestringTarget table name

Example​

Controller
$db = new \Fegg\Database\Pdo();

$record = $db->setWhere('category = ?', 2)->count('cms_news')->execute()->one();
$count = (int) $record['number_of_records'];