getCount()
Returns the number of rows matched or affected by the last executed query. Works for SELECT, UPDATE and DELETE operations.
Signature:
public function getCount(): int
Basic Example
// Get all active users
$db->where('status', 'active');
$users = $db->get('test_users');
echo "Found " . $db->getCount() . " active users.";
Use Cases
- Count how many rows were returned by
get()
- Check how many rows were updated or deleted
- Display dynamic counters in dashboards or paginators
Deprecated: The method
$db->count
is deprecated and has been removed as of v1.5.x
.
Use Instead: Use
getCount()
for instance-safe tracking of affected row counts.
The legacy $db->count
relied on a static variable and could produce incorrect results in multi-instance environments.