BaseModel::count

Usage

int BaseModel::count([ string $where_sql = '' ], [ ... $args ])

Description

Get the number of records within the database table with optional where clause.

Parameters

Parameter Required Type Description
$where_sql No string Optional where clause for cases where you want to retrieve the number of records based on a condition. Can contain placeholders (eg. %s, %i, %b, et al).
$args No desc=

Return Value

Integer of how many records matched within the database table.

Examples

Get Total Number of Products


use App\Demo\Products; // Get total $total = Product::count(); echo "There are total of $total products.\n";

Get Number of Orders of Product id# 62


use App\Demo\Models\Order; // Get total tims product id# 62 was ordered $id = 62; $total = Order::count('product_id = %i', $id); echo "Product was ordered $total times.\n";

See Also