delete()
The delete() method removes one or more rows from a table based on specified conditions. It supports prepared statements and returns true on success or false on failure.
Signature:
public function delete(string $tableName, int|array|null $numRows = null): bool
Basic Usage
$db->where('id', 42);
$success = $db->delete('test_users');
Delete with LIMIT
You can restrict the number of affected rows using the optional $numRows parameter:
$db->where('status', 'inactive');
$db->delete('test_users', 10); // Delete max 10 users
Return Value
trueon successfalseon failure (checkgetLastError())
Notes
- Always use a
where()condition to avoid deleting all rows unintentionally - Prepared statements protect against SQL injection
- Supports JOIN-based deletes if needed (see advanced examples)
- The optional
$numRowscan be an integer or array (e.g. [10, 20])