Delete

The Delete class is used to build SQL DELETE statements. It extends the base Query class and inherits its WHERE clause capabilities.

Methods

addFlag($flag)

Adds a MySQL-specific flag to the DELETE statement. Supported flags include IGNORE, LOW_PRIORITY, and QUICK.

Example:

use Staple\Query\Delete;

$delete = new Delete('logs');
$delete->addFlag(Delete::QUICK);
// Result: DELETE QUICK FROM logs

where($column, $operator, $value)

Adds a WHERE condition to the DELETE query. Inherited from Query.

Example:

use Staple\Query\Delete;

$delete = new Delete('users');
$delete->where('last_login', '<', '2024-01-01');
// Result: DELETE FROM users WHERE last_login < :last_login

leftJoin($table, $condition, $alias, $schema)

Adds a LEFT JOIN to the DELETE statement.

Example:

use Staple\Query\Delete;

$delete = new Delete('users');
$delete->leftJoin('profiles', 'users.id = profiles.user_id');

innerJoin($table, $condition, $alias, $schema)

Adds an INNER JOIN to the DELETE statement.

build()

Builds and returns the SQL string for the DELETE statement.

Example:

$delete = new Delete('sessions');
$delete->where('id', '=', 'abc123');
echo $delete->build();
// Result: DELETE FROM sessions WHERE id = :id

execute()

Executes the DELETE query on the database. Inherited from Query.

Example:

$delete = new Delete('temp_data');
$delete->where('created_at', '<', date('Y-m-d', strtotime('-7 days')));
$delete->execute();