Count
Purpose
The count
method calculates the number of records in the 'User' table that meet specific criteria. It provides flexibility by allowing counts to be detailed per field or overall, enhancing data analysis capabilities.
Parameters
array $criteria
- An associative array of criteria for selecting the records to be counted. Keys represent column names, and values represent conditions those fields must meet.bool $format
- Optional. When set to true, returns the count as an object; otherwise, as an array or integer based on the query structure.
Return Value
Depending on the provided criteria and format parameter, this method can return an integer, an array, or an object representing the count of records that match the criteria.
Error Handling
If the operation encounters an error, an exception is thrown. This ensures that potential issues are effectively communicated and can be handled appropriately.
Example Usage
$completedCount = $prisma->user->count();
echo "<pre>";
print_r($completedCount);
echo "</pre>";
Example Usage
$completedCount = $prisma->user->count([
'where' => [
'name' => [
'contains' => 'John Doe',
],
]
]);
echo "<pre>";
print_r($completedCount);
echo "</pre>";
Example Usage With Select
$userCount = $prisma->user->count([
'where' => [
'name' => ['contains' => 'John Doe'],
],
'select' => [
'id' => true,
'age' => true,
],
]);
echo "<pre>";
print_r($userCount);
echo "</pre>";